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
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:.)
)