开发者

equivalent for regexp /<rr>(.*?)</rr>/<test>$1</test>/gi

I want to write simple program in C equivalent to the regular expression:

/<rr>(.*?)<\/rr>/<test>$1<\/test>/gi. 

Does anyone have example开发者_StackOverflows?


It helps if you understand what the regex is supposed to do.

The pattern

The parentheses (...) indicate the beginning and end of a group. They also create a backreference to be used later.

The . is a metacharacter that matches any character.

The * repetition specifier can be used to match "zero-or-more times" of the preceding pattern.

The ? is used here to make the preceding quantifier "lazy" instead of "greedy."

The $1 is likely (depends on the language) a reference to the first capture group. In this case it would be everything matched by (.*?)

The /g modifier at the end is used to perform a global match (find all matches rather than stopping after the first match).

The /i modifier is used to make case-insensitive matches

References

  • regular-expressions.info, Grouping, Dot, Repetition: *+?{…}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜