开发者

Regexp: group for every found item (PCRE)

开发者 https://www.devze.com 2023-02-15 13:48 出处:网络
I am using PCRE with C++ (Borland) and want to get all matches of a group. ^(\\w+\\s)(\\w+\\s)*(\\w+)$

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

精彩评论

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

关注公众号