Need extra help with your Joomla site? Consider paid Joomla support by the developer of Chameleon and MetaMod.
- Index
- » Chameleon / ChameleonLite
- » Chameleon
- » How to use Regex in a url
How to use Regex in a url
How to use Regex in a url
I'm new to using regex and am trying to detect a variable number between 1 & 5000 using a regex expression in a page url rule. Do I use the normal start and end delimiters ^ $ within the url? The example in the documentation is showing hash's and in one of the posts something completely different so I'm not sure the correct syntax.
Thanks for your help.
Re: How to use Regex in a url
Hi,
the regexes need to start and end with a delimiter. It's fairly traditional in PHP to use a forward slash (/), but since that's often found in the string that you are searching, then I prefer to use a # instead. The search pattern than has to start and end with that character. It's actually completely optional as to what character you use as per the PHP spec, but it has to be the same on both ends.
The ^ and $ (if you want to use them) go inside the end characters.
e.g. #^http://www\.mysite\.com/mypage123$#
(remembering to escape the "." characters with a backslash)
Ok, for isolating numbers between 1 and 5000 with regex, that's quite tricky. I think I'd do it this way, with alternatives for the different number of digits (1-4). This will catch the numbers 0-9, 10-99, 100-999, 1000-4999, and 5000. I've use an example of a url that ends in mypage.html?id=digits
#mypage\.html\?id=(([0-9])|([1-9][0-9])|([1-9][0-9][0-9])|([1-4][0-9][0-9][0-9])|5000)$#
Hope that helps,
Stephen
Re: How to use Regex in a url
Page1 or page2:
#^(page1|page2)\.html$#
I don't think you really want to detect page1 AND page2: the page can't be both things at once, so I think you're wanting the "OR" version above.
Cheers,
Stephen
- Index
- » Chameleon / ChameleonLite
- » Chameleon
- » How to use Regex in a url
Board Info
- Board Stats:
- Total Topics:
- 1699
- Total Polls:
- 6
- Total Posts:
- 5965
- Posts this week:
- 4
- User Info:
- Total Users:
- 8011
- Newest User:
- ignac84502
- Members Online:
- 0
- Guests Online:
- 94
- Online:
- There are no members online
Forum Legend:
Topic
New
Locked
Sticky
Active
New/Active
New/Locked
New Sticky
Locked/Active
Active/Sticky
Sticky/Locked
Sticky/Active/Locked