开发者

Matching inner pattern an unlimited amount of times within outer pattern

Say I have the following pattern:

INDICATOR\s+([a-z0-9]+)

which would match for example:

INDICATOR AA or INDICATOR B3

I need to edit this pattern so it matches any instances of a string which starts with INDICATOR has a space and then h开发者_如何学JAVAas multiple matches of the inner pattern e.g.

INDICATOR AA A3 66 B8 34 CD

INDICATOR BG 4D CS

INDICATOR HG

Is it possible to do this?

Solution

With thanks to Gumbo I came up with the following regex which suits my requirements:

INDICATOR((\s+)?([,-])?(\s+)?([a-z0-9]+))+


Try this:

INDICATOR(\s+([a-z0-9]+))+

Here the repeating pattern is wrapped in a group and quantified using + to allow one or more repetitions of the expression inside the group. But you won’t get every match of the inner group with this but only the last match (or to be more specific: it depends on the implementation you’re using).

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜