I want to match and group any of these listed words:
aboutus/
,race/
,cruise/
,westerlies/
,weather/
,reach/
,gear/
or empty_string
Here is a solution, but which will not match the empty_string:
^(aboutus|race|cruise|westerlies|weather|reach|gear)/$
So my question is: How to include Empty string in this matching?
I still don't get a good solution for this.
So I added one more regex specially for empty_string:ie ^$
.
Note: these regular expression is for django urls.py
.
update: It will be better if the capturing group does not contain /
try this:
^(aboutus|race|cruise|westerlies|weather|reach|gear)?/$
edit: if '/' is in every case except the empty string try this
^((aboutus|race|cruise|westerlies|weather|reach|gear)(/))?$
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With