I have a input string
this or "that or" or 'this or that'
that should be translated to
this || "that or" || "this or that"
So the attempt is to look for an occurence of a string ( or ) within a string and replace it with another string ( || ). I have tried the following code
Pattern.compile("( or )(?:('.*?'|".*?"|\S+)\1.)*?").matcher("this or "that or" or 'this or that'").replaceAll(" || ")
The output is
this || "that or" || 'this || that'
The problem being that string within the single quote was also replaced. As for the code, the style is just for an example. I would compile the pattern and reuse it when I get this to work.
See Question&Answers more detail:os