Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-15-2010, 02:49 AM   PM User | #1
styks1987
New to the CF scene

 
Join Date: Aug 2010
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
styks1987 is an unknown quantity at this point
Regular Expression Solution

I am pulling a URL from the address bar and parse it down until I get this
(The 'sortby' changes so I have to detect it dynamically)

sortby=industry&tuition=true

OR

sortby=industry

I want this to return

tuition=true

OR

Nothing

This is the regex I am currently using. It works for one but not the other.
/(^sortby=)[A-Za-z|\_|\+|\W]{1,}&/

Thank you for you time!

Michael
styks1987 is offline   Reply With Quote
Old 10-15-2010, 04:41 AM   PM User | #2
Keleth
Senior Coder

 
Join Date: Jun 2008
Location: New Jersey
Posts: 2,354
Thanks: 45
Thanked 247 Times in 244 Posts
Keleth is on a distinguished road
Can sortby be anything but letters? If not

Code:
/^sortby=[a-z]+&?/
You don't need sortby= to be grouped, unless you're trying to capture it, but as its static, that serves no purpose. I think in your range, you were trying to add in A-Z or a-z or underscore or plus or word... that's not really necessary. First will you ever have a non-letter? If not, a-z is fine, then the i at the end for case insensitive. Finally, {1,} is the same as +. So use +. What you forgot is your second example doesn't have the &, but sometimes it might be there. So ? for 0 or 1.
Keleth is offline   Reply With Quote
Old 10-15-2010, 04:41 AM   PM User | #3
Keleth
Senior Coder

 
Join Date: Jun 2008
Location: New Jersey
Posts: 2,354
Thanks: 45
Thanked 247 Times in 244 Posts
Keleth is on a distinguished road
Can sortby be anything but letters? If not

Code:
/^sortby=[a-z]+&?/
You don't need sortby= to be grouped, unless you're trying to capture it, but as its static, that serves no purpose. I think in your range, you were trying to add in A-Z or a-z or underscore or plus or word... that's not really necessary. First will you ever have a non-letter? If not, a-z is fine, then the i at the end for case insensitive. Finally, {1,} is the same as +. So use +. What you forgot is your second example doesn't have the &, but sometimes it might be there. So ? for 0 or 1.
Keleth is offline   Reply With Quote
Reply

Bookmarks

Tags
php, regex, regular expression, url

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:21 AM.


Advertisement
Log in to turn off these ads.