Skip to content
New issue

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

创建一个捕获组,以便提取数据 #7

Open
BiYuqi opened this issue Jan 23, 2019 · 0 comments
Open

创建一个捕获组,以便提取数据 #7

BiYuqi opened this issue Jan 23, 2019 · 0 comments

Comments

@BiYuqi
Copy link
Owner

BiYuqi commented Jan 23, 2019

聊聊捕获组

如果想要重复匹配多个字符该怎么办?这里可以用小括号来指定子表达式(也叫做分组).

问题

需要匹配xi,并分组

const str = 'xixixi xii xix'
正则
/(xi)+/g
关键字的匹配一般使用锚点(即该关键字)进行匹配,这里使用xi,括号即捕获
str.match(/(xi)+/g)
// ["xixixi", "xi", "xi"]

2019-01-23 22 13 43

在线测试

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant