开发者

Regexp: group for every found item (PCRE)

I am using PCRE with C++ (Borland) and want to get all matches of a group.

^(\w+\s)(\w+\s)*(\w+)$

input 1: first s开发者_JAVA百科econd third results in 3 groups (first, second and third)

input 2:first second second third results in 3 groups (first, second and third) too, but I need 4 groups.

The second word is optinal and occurs 0 - n times.

// EDIT:


PCRE seems to have a split function, so if you know your delimiters are a group of whitespace, you should split the text and, depending on the count of splitted fields, react accordingly.

Regards

rbo


I think your best shot is to match :

^(\w+\s)((?:\w+\s)*)(\w+)$

and then match the inside x words by hand, looking for \s with string comparison.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜