正则几个常用的方法

exec:对string进行正则处理,并返回匹配结果.array[0]为原字符串,array[i]为匹配在整个被搜索字符串中的位置。
test:测试string是否包含有匹配结果,包含返回true,不包含返回false。
match(pattern) :根据pattern进行正则匹配,如果匹配到,返回匹配结果,如匹配不到返回null
search(pattern) :根据pattern进行正则匹配,如果匹配到一个结果,则返回它的索引数;否则返回-1
replace(pattern,replacement) :根据pattern进行正则匹配,把匹配结果替换为replacement
split(pattern) :根据pattern进行正则分割,返回一个分割的数组

原文地址:https://www.cnblogs.com/binmengxue/p/5542974.html