I need to get all operators (arithmetic, comparison, logical...) in a string...
((value+10)*10)>=300 || (array[key]-20==0&&"foo==bar"!=="")
...and add a single whitespace before and after them (if doesn't already exists)...
((value + 10) * 10) >= 300 || (array[key] - 20 == 0 && "foo==bar" !== "")
...ignoring what is between quotes or single quotes.
Aditional rules:
- add space only before pre-in/decrement operators
- add space only after post-in/decrement operators
Sounds easy but I can't get how I could do it using regex in PHP. Thanks if someone can help!
I'm trying to do something like $str = preg_replace('(?<=[\w\]\)\s\"\'])\!=(?=[\w\]\)\s\"\'])', ' != ', $str); for every operator, but I don't think it's a good idea.
(-20+3)be(- 20 + 3)or(-20 + 3)?