I have the following patterns and grouping application which I am refactoring in one. The following will be placed in a xml file and read into a regex engine:
regexpattern="http://cars.mysite.com(.*)" application="http://www.mysite.com$1"
regexpattern="http://ww.mysite.com(.*)" application="http://www.mysite.com$1
regexpattern="http://(bikes\.|new\.|)mysite.com/(.*)" application="http://www.mysite.com/$2"
combined into this:
regexpattern="http://(cars\.|ww\.|bikes\.|new\.|)mysite.com(|/)(.*)" application="http://www.mysite.com/$3"
Is this the best I could do, can it be done better? I am new to this. Thanks.
1. You have a missing backslash:
http://(cars\.|ww\.|bikes\.|new\.|)mysite\.com(|/)(.*) ^2. Instead of
(|/)you can use/?:http://(cars\.|ww\.|bikes\.|new\.|)mysite\.com/?(.*) ^^3. Making the slash optional means that it accepts things like
mysite.com.co.ukwhich is probably not what you want.4. Another minor change is to write
\.only once:http://((cars|ww|bikes|new)\.)?mysite\.com/?(.*) ^^