I am trying to perform a global substitution in perl on a string on a basis of a certain pattern NOT matching before or after a certain match. Basically, I have an xml tag and want to keep it if a match occurs within ten characters before or after the tag, but remove the xml tag if not.
so, if I have a string which contains:
foo something<xml tag>bar<\xml tag> something
No substitution will occur, but if a string is
something <xml tag>bar<\xml tag> something
it would be replaced with:
something bar something
What I tried is:
$string =~ s/(?<!foo.{0,10})<xml tag>(bar)<\/xml tag> |<xml tag>(bar)<\/xml tag>(?!.{0,10}foo)/$1/g;
But I got this error:
Variable length lookbehind not implemented in regex
I'm not really sure how to do this. Help?