javascript - js里的正则匹配能有类似php里的PREG_OFFSET_CAPTURE功能吗

WBOY
Release: 2016-06-06 20:43:06
Original
1106 people have browsed it

目前发现它的结果里只包含了匹配到的字符串,如果我想获得字符串的位置信息应该怎么办呢?

回复内容:

目前发现它的结果里只包含了匹配到的字符串,如果我想获得字符串的位置信息应该怎么办呢?

js的replace第二个参数可以传一个回调函数,回调函数的第一个参数是匹配项,第二个参数就是字符串位置

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template