Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Aug 2010
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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

  • #2
    Senior Coder
    Join Date
    Jun 2008
    Location
    New Jersey
    Posts
    2,530
    Thanks
    45
    Thanked 259 Times in 256 Posts
    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.

  • #3
    Senior Coder
    Join Date
    Jun 2008
    Location
    New Jersey
    Posts
    2,530
    Thanks
    45
    Thanked 259 Times in 256 Posts
    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.


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •