ios - RegEx negative-lookahead and behind to find characters not embedded within a wrapper -
i match strings/characters not surrounded well-defined string-wrapper. in case wrapper '@l@' on left of string , '@r@' on right of string.
with following string example:
this @l@string@r@ , it's @l@good or ok@r@ change characters in next string
i able search (any number of characters) change them on case case basis. example:
- searching "in", match twice - word 'in', , 'in' contained within last word 'string'.
- searching "g", should found within word 'change' , in final word string (but not first occurrence of string contained within wrapper).
i'm familiar how lookahead works in sense identifies match, , doesn't return matching criteria part of identified match. unfortunately, can't head around how it.
i've been playing @ http://regexpal.com/ can't seem find works. examples i've found ios problematic, perhaps javascript tester tiny bit different.
i took guidance previous question asked, seemed same sufficiently different mean couldn't work out how reuse it:
replacing 'non-tagged' content in web page
any ideas?
at first @l@
@r@
blocks , use alternation operator |
match string in
remaining string. differentiate matches, put in
inside capturing group.
@l@.*?@r@|(in)
or
use negative lookahead assertion. match sub-string in
if it's not followed @l@
or @r@
, 0 or more times , further followed @r@
. match in
's not present inside @l@
, @r@
blocks.
in(?!(?:(?!@[rl]@).)*@r@)
Comments
Post a Comment