I really need some help forming a regex pattern in java.
I am trying to replace all occurrences of a given word provided that it is not enclosed within a less-than or greater-than sign. It should not replace it even if the less/greater-than signs are not directly next to the word. Here is my most recent attempt:
stringIn = stringIn.replaceAll("((?:<[^>]>[^<]*)+" + word + "(?:<[^>]>[^<]*)+)", "$1<" + newWord + ">$2");
But this does not seem to replace the word not in brackets. Just to clarify I made up an example replacement:
"foo word <word> <foo word foo>" should go to
"foo <newWord> <word> <foo word foo>
PS Just saw this SO question and it looks similar but I don't really understand it and cannot guaranty it as it refers to PHP not Java.