Regex match occurrences only after character sequence

前端 未结 1 831
忘了有多久
忘了有多久 2021-01-21 10:40

I want to find all the characters after w\'s that occur in this string, but only the ones after foo

edward woodward foo edward woodward
相关标签:
1条回答
  • 2021-01-21 11:40

    You may use the following regex with a PCRE engine:

    (?:\bfoo\b|\G(?!^))[^w]*w\K.
    

    See the regex demo.

    Details

    • (?:\bfoo\b|\G(?!^)) - either a whole word foo (\bfoo\b) or (|) the end of the previous match (\G(?!^))
    • [^w]* - any 0+ chars other than w
    • w - a w char
    • \K - match reset operator discarding all text matched so far
    • . - any char (other than line break chars, if you need to match them with . add (?s) at the pattern start or replace . with (?s:.))
    0 讨论(0)
提交回复
热议问题