I'm having problems finding and replacing portions of a string using regex in scala.
Given the following string: q[k6.q3]>=0 and q[dist.report][0] or q[dist.report][1] and q[10]>20
I want to replace all the occurrences of "and" and "or" with "&&" and "||".
The regex I have come up with is: .+\s((and|or)+)\s.+. However, this seems to only find the last "and".
When using https://regex101.com/#pcre I tried to solve this by adding the modifiers gU, which seems to work. But I'm not sure how to use those modifiers in Scala code.
Any help is much appreciated
Why not to use solution like:
str.replaceAll("\\sand\\s", " && ").replaceAll("\\sor\\s", " || ")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With