A common problem when creating a vanity or redirect URL is that users might leave the plural off the end.
What's the best way to match all of the following?:
- /parksprojects
- /parksproject
- /parkproject
- /parkprojects
^/park[s|*]project*$ ?
Any suggestions are appreciated, thanks in advance!
You can use
^\/parks?projects?$. This regex matches all the cases in your example, tested on regex101.comThe
?after thesmeans that the letter is optional and might not be there.If you want the regex to match your string anywhere in the content, such as an URL or as part of a more complex string, you can use
\/parks?projects?without beginning and ending markers.regex101.com proof that the regex works
If you have more examples I could be more precise.