can not get multiple matches using regex

157 views
Skip to first unread message

bhomass

unread,
Dec 13, 2012, 8:08:30 PM12/13/12
to google-we...@googlegroups.com
I am using GWT Regex

RegExp regExp = RegExp.compile("\\b" + searchWord + "\\b", "gi");
        MatchResult matcher = regExp.exec(input);

this only returns the first match. why is that? I already set the global option. any one knows how to get multiple match return?

Thomas Broyer

unread,
Dec 14, 2012, 8:48:53 AM12/14/12
to google-we...@googlegroups.com
Call exec() again with the same 'input'. See the bottom of https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/RegExp/exec

bhomass

unread,
Dec 15, 2012, 3:36:36 PM12/15/12
to google-we...@googlegroups.com
in that case, what is the point of matchResult.getGroupCount()? it is always 1.

Thomas Broyer

unread,
Dec 16, 2012, 2:38:27 PM12/16/12
to google-we...@googlegroups.com


On Saturday, December 15, 2012 9:36:36 PM UTC+1, bhomass wrote:
in that case, what is the point of matchResult.getGroupCount()? it is always 1.

Groups in regexps are those things between parentheses. In "a(b+)c" matching against "abbc", there would be 2 groups, the first one (group 0) would be "abbc" while the second one (group 1) would be "bb".
Reply all
Reply to author
Forward
0 new messages