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
' hello world '.replace(/\s*/, '') 输出"hello world ",只匹配了第一个空格并替换
用全局匹配可以全部替换
' hello world '.replace(/\s*/g, '') 输出"helloworld",空格都替换掉了
let reg = /^\s*/;
使用RegExp类来做的话,我们需要构建一个实例,像这样:
let reg = new RegExp('^\\s*') // 这种直接使用字符串,斜杠要多打一个,不然生成的正则表达式没转义符
当然这样也行:
let reg = new RegExp(/^\s*/);
// 有如下正则 /.{2}/
这个表示任意符号匹配两个,此时未加^和$,我们给出wweerr,它会把ww ee rr分别都匹配到,所以要精确匹配需要加^和$,像这样/^.{2}$/它只会匹配两个,多的都不认!
wweerr
ww ee rr
/^.{2}$/
The text was updated successfully, but these errors were encountered:
No branches or pull requests
用全局匹配可以全部替换
使用RegExp类来做的话,我们需要构建一个实例,像这样:
当然这样也行:
给个栗子就清楚了,如下:
这个表示任意符号匹配两个,此时未加^和$,我们给出
wweerr
,它会把ww ee rr
分别都匹配到,所以要精确匹配需要加^和$,像这样/^.{2}$/
它只会匹配两个,多的都不认!The text was updated successfully, but these errors were encountered: