#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    218
    Rep Power
    11

    Regular Expression with A-Z 0-9 . ( ) characters


    Hello,
    I am trying to make a regular expression that will match any string with a a-z 0-9 or a parentheses or period.

    Can anyone help?

    I have a regex ([a-z]+) but that only works for a-z characters and im confused on how to add to that regex to support othe characters.

    Thanks!
  2. #2
  3. Come play with me!
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    13,742
    Rep Power
    9397
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    218
    Rep Power
    11
    i tried this


    ([a-z].()+) but doesnt work
  6. #4
  7. Come play with me!
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    13,742
    Rep Power
    9397
    Originally Posted by scooterp83
    i tried this


    ([a-z].()+) but doesnt work
    Then try something else. You're close.

    The solution is quite simple. Give yourself a chance.
  8. #5
  9. CSS & JS/DOM Adept
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jul 2004
    Location
    USA (verifiably)
    Posts
    20,122
    Rep Power
    4258
    We don't have to make him guess, requinix.

    scooter, check this out: http://www.regular-expressions.info/charclass.html

    Comments on this post

    • requinix agrees : don't *have* to, no... :D too many programmers are afraid to experiment a bit
    Spreading knowledge, one newbie at a time.

    Check out my blog. | Learn CSS. | PHP includes | X/HTML Validator | CSS validator | Common CSS Mistakes | Common JS Mistakes

    Remember people spend most of their time on other people's sites (so don't violate web design conventions).
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    218
    Rep Power
    11
    So i used the follwing

    ([a-z\.*\(*\)*]+)


    however this is not matching the string "cranston"


    any idea?
  12. #7
  13. CSS & JS/DOM Adept
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jul 2004
    Location
    USA (verifiably)
    Posts
    20,122
    Rep Power
    4258
    I thought the asterisk was not one of the characters you wanted to match? Inside a character set it loses it's special meaning.

    Otherwise, it works fine for me. What language are you using it with? Perhaps the issue is not with the expression itself now, so please show us how you're using it.
    Spreading knowledge, one newbie at a time.

    Check out my blog. | Learn CSS. | PHP includes | X/HTML Validator | CSS validator | Common CSS Mistakes | Common JS Mistakes

    Remember people spend most of their time on other people's sites (so don't violate web design conventions).
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    218
    Rep Power
    11
    im using the * to say 0 or many times. So the regex ([a-z\.*\(*\)*]+)


    will work with a string that has

    a-z
    a period 0 or many times
    a ( 0 or many times
    a ( 0 or many times.

    Is this not how its written? Can someone tell me simply how I can make a regex to allow a string with letters, period ( or ).

    For example these are all valid matches


    blah
    blah.blah
    blah. Hello (Blah)
    blah (blah)


    It can be just letters or it can have letters an a period or letters and parentheses or all scenarios?
  16. #9
  17. CSS & JS/DOM Adept
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jul 2004
    Location
    USA (verifiably)
    Posts
    20,122
    Rep Power
    4258
    Let me try to explain again. The pair of "[" and "]" brackets delimit a character class/set. Inside it some meta-characters (including "*", "+", and "?") lose their special meaning, so they are used literally. Each character is a character class will be able to match, but does not have to match any characters.

    For instance, the expression "/([a-z\.\(\)]+)/" will match "alpha(one)", "sheepdog", and "example.com".
    Spreading knowledge, one newbie at a time.

    Check out my blog. | Learn CSS. | PHP includes | X/HTML Validator | CSS validator | Common CSS Mistakes | Common JS Mistakes

    Remember people spend most of their time on other people's sites (so don't violate web design conventions).

IMN logo majestic logo threadwatch logo seochat tools logo