Question:
How do I convert var x+=1+2+3+(5+6+7) to var x += 1 + 2 + 3 + ( 5 + 6 + 7 )
Details:
Using regular expressions, something like :%s/+/\ x\ /g won’t work because it will convert += to + = (amongst other problems). So instead one would use negations (negatives, nots, whatever they’re called) like so :%s/\s\@!+/\ +/g, which is about as complicated a way as one can say “plus sign without an empty space before it”. But now this converts something like x++ into x + +. What I need is something more complex. I need more than one constraint in the negation, and an additional constraint afterwards. Something like so, but this doesn’t work :%s/[\s+]\@!+\x\@!/\ +/g
Could someone please provide the one, or possibly two regex statements which will pad out an example operator, such that I can model the rest of my rules on it/them.
Motivation:
I find beautifiers for languages like javascript or PHP don’t give me full control (see here). Therefore, I am attempting to use regex to carry out the following conversions:
foo(1,2,3,4)→foo( 1, 2, 3, 4 )var x=1*2*3→var x = 1 * 2 * 3var x=1%2%3→var x = 1 % 2 % 3var x=a&&b&&c→var x = a && b && cvar x=a&b&c→var x = a & b & c
Any feedback would also be appreciated
Thanks to the great feedback, I now have a regular expression like so to work from. I am running these two regular expressions:
And it is working fairly well. Here are some results.
It seems to work fine for everything except nested brackets. If I fix the nested brackets problem, I will update it here.