I’m trying to do link rewriting in my mobile application (written in ruby). I would like it to be able to accomplish both of these rewrites with a single regular expression:
m.example.com -> www.example.com
m.subd.example.com -> subd.example.com
The closest I’ve gotten replacing this:
m\.([a-z\.]*)example\.com
with this:
$1example.com
This works for the m.subd.example.com but it fails for m.example.com because of my “www.” exception.
I do this A LOT so i’d like it to be very fast, which is why I am trying to avoid using any code, just a single regex. Is it possible? Is there a fancy feature of regex that I don’t know about?
Regex is code. A more complex regex takes longer to run. You’ll need to write some code or run two regexes.