Welcome to the MetaMod and Chameleon Support Forums.

Before posting, please check out the FAQs.


Mobilepro
Beginner Modder
ranks
useravatar
User Info

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.


Administrator has disabled public posting
metamodguy
useravatar
User Info

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


Stephen Brandon
MetaMod / Chameleon developer
If you use MetaMod or Chameleon, please post a rating and a review at the Joomla! Extensions Directory

Administrator has disabled public posting
Vseva
Beginner Modder
ranks
useravatar
User Info

Re: How to use Regex in a url

Hi !

How can we regex two different things in Page URL?

ex: page1 or page2
or
ex: page1 and page2


Administrator has disabled public posting
metamodguy
useravatar
User Info

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


Stephen Brandon
MetaMod / Chameleon developer
If you use MetaMod or Chameleon, please post a rating and a review at the Joomla! Extensions Directory

Administrator has disabled public posting
Vseva
Beginner Modder
ranks
useravatar
User Info

Re: How to use Regex in a url

Thank Stephen.


Administrator has disabled public posting

Board Info

Board Stats:   Total Users: 3079  Total Topics: 1195  Total Polls: 7  Total Posts: 4448  Posts this week: 18
User Info:   Newest User :  raisaalam   Members Online: 1   Guests Online: 81
Online 
Jeff78
Topic
New
Locked
Topic
New
Locked
Sticky
Active
New/Active
Sticky
Active
New/Active
New/Closed
New Sticky
Closed/Active
New/Locked
New Sticky
Locked/Active
Active/Sticky
Sticky/Locked
Sticky Active Locked
Active/Sticky
Sticky/Locked
Sticky/Active/Locked