We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
正则表达式regex是用于匹配字符串中字符组合的模式,由参数pattern + 标志flags构成。
regex
pattern
flags
指所有字母、数字、符号等
指换行、回车、空白等不会实际显示出来的字符
指定匹配前面的子表达式必须要出现多少次才能满足
描述字符串定边界
组,应用于限制多选结构的范围/分组/捕获文本/环视/特殊模式处理
单个匹配,字符集/排除字符集/命名字符集
有6个标志,可单独或一起使用
有以下两种方式构建一个正则表达式:
pattern/flags
const regex = /ab+c/; const regex = /hello/gi;
new RegExp(pattern [, flags])
let regex = new RegExp("ab+c"); let regex = new RegExp(/hello/, "gi"); let regex = new RegExp(/hello/gi); let regex = new RegExp("hello", "gi");
let regex = /nn/; let str = 'runnobnnnbnn';
regex.exec(str) // ["nn", index: 6, input: "runnobnnnbnn", groups: undefined] str.match(regex) // ["nn", "nn", "nn"]
The text was updated successfully, but these errors were encountered:
No branches or pull requests
定义
正则表达式
regex
是用于匹配字符串中字符组合的模式,由参数pattern
+ 标志flags
构成。参数
普通字符
指所有字母、数字、符号等
非打印字符
指换行、回车、空白等不会实际显示出来的字符
限定符
指定匹配前面的子表达式必须要出现多少次才能满足
定位符
描述字符串定边界
圆括号
组,应用于限制多选结构的范围/分组/捕获文本/环视/特殊模式处理
中括号
单个匹配,字符集/排除字符集/命名字符集
其他特殊字符
标志
有6个标志,可单独或一起使用
创建
有以下两种方式构建一个正则表达式:
pattern/flags
new RegExp(pattern [, flags])
使用
参考文档
The text was updated successfully, but these errors were encountered: