正则表达式相关方法总结

2018-11-24  本文已影响0人  Jerry379

RegExp实例方法

var text = "mom and data and baby";
var pattern = /mom( and data( and baby)?)?/gi;
var matches = pattern.exec(text)

//0: "mom and data and baby"
//1: " and data and baby"
//2: " and baby"
//groups: undefined
//index: 0
//input: "mom and data and baby"
//length: 3

在字符串中可以使用正则表达式的方法

上一篇下一篇

猜你喜欢

热点阅读