Javascript正则表达式匹配捕获返回整个匹配,而不是组 [英] Javascript Regex Match Capture is returning whole match, not group

查看:69
本文介绍了Javascript正则表达式匹配捕获返回整个匹配,而不是组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

re = /\s{1,}(male)\.$/gi

"A girl is a female, and a boy is a male.".match(re);

这导致男性。

我想要的是男性

我把男性放在括号中,但我会抓住那个群体。

I put male in parenthesis and I though that would capture just that group.

感谢您的帮助

推荐答案

您需要在正则表达式中取出'g'选项:

You need to take out the 'g' option on your regexp:

re = /\s{1,}(male)\.$/i

收益率

[" male.", "male"]

这篇关于Javascript正则表达式匹配捕获返回整个匹配,而不是组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆