Regex for circular replacement

Posted by polygenelubricants on Stack Overflow See other posts from Stack Overflow or by polygenelubricants
Published on 2010-03-15T07:18:07Z Indexed on 2010/03/15 7:39 UTC
Read the original article Hit count: 573

How would you use regex to write functions to do the following:

  1. Replace lowercase 'a' with uppercase and vice versa
  2. Where words are separated by whitespaces and > and < are special markers, replace >word with word< and vice versa
  3. 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:

© Stack Overflow or respective owner

Related posts about java

Related posts about regex