January 30th, 2010, 06:48 PM
Regular Expression with A-Z 0-9 . ( ) characters
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.
January 30th, 2010, 06:52 PM
Have you tried simply adding them?
January 30th, 2010, 06:54 PM
i tried this
([a-z].()+) but doesnt work
January 30th, 2010, 07:37 PM
Then try something else. You're close.
Originally Posted by scooterp83
The solution is quite simple. Give yourself a chance.
January 30th, 2010, 07:42 PM
January 31st, 2010, 02:05 AM
So i used the follwing
however this is not matching the string "cranston"
January 31st, 2010, 11:09 AM
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.
January 31st, 2010, 12:54 PM
im using the * to say 0 or many times. So the regex ([a-z\.*\(*\)*]+)
will work with a string that has
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. Hello (Blah)
It can be just letters or it can have letters an a period or letters and parentheses or all scenarios?
January 31st, 2010, 01:02 PM
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".