Regex for circular replacement
- by polygenelubricants
How would you use regex to write functions to do the following:
Replace lowercase 'a' with uppercase and vice versa
Where words are separated by whitespaces and > and < are special markers, replace >word with word< and vice versa
Replace postincrement (i++;) with preincrement (++i;) and vice versa. Variable names are [a-z]+. Input is just a bunch of these statements. Bonus: also do decrement.
Also interested in solutions in other flavors.
Note: this is NOT a homework question. See also my previous explorations of regex:
Regex split into overlapping strings (Alan Moore's answer is especially instructive)
Can you use zero-width matching regex in String split? (my solution exploits a known Java regex bug with regards to non-obvious length lookbehind!)