1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Regular Expression Help - How do I match a format?

Discussion in 'General Scripting Chat' started by loopline, Oct 10, 2011.

  1. loopline

    loopline Jr. VIP Jr. VIP

    Joined:
    Jan 25, 2009
    Messages:
    3,383
    Likes Received:
    1,801
    Gender:
    Male
    Home Page:
    Hey all, I know enough about regular expressions to be dangerous. I would like to match this format:
    Code:
    broadway-basketeers-deluxe-chocolate-and-nut-collection-gourmet-snack-gift-basket
    I don't want to match the words exactly, but what I want to match is words with dashes inbetween.

    So basically

    xxxx-xxxx-xxxx-xxxx-xxxx


    To see if I can make it more complex here the words could be anything, and any length, so

    xx-xxxxxxx-xxxxx

    or

    xxxxx-xxxxxxxxxxx-xx-xxxxxxxx-xxxxxxxxx

    etc...

    How do I do this effectively?

    At least it would be two words with a dash, at most probably 16 words with dashes between.

    Allowing for numbers in addtion to words would be ideal.


    Also anything that ends with .html I don't want.

    So

    xxxx-xxxxx-xxxxx-xxxxxxxxx.html

    I don't want that, I only want it if its just words and dashes.

    I am trying to build an url filter.

    Any ideas on how I could do this?

    Thanks in advance for your time.
     
    Last edited: Oct 10, 2011
  2. loopline

    loopline Jr. VIP Jr. VIP

    Joined:
    Jan 25, 2009
    Messages:
    3,383
    Likes Received:
    1,801
    Gender:
    Male
    Home Page:
    Someone figured it out for me. If anyone else is in need of it, here it is:

    ([a-z0-9-]+)