Regular Expression Help
| From: | Pablo Gosse | Date: | Wed, 30 Jun 2004 20:57:02 +0000 |
| Subject: | Regular Expression Help | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-189369@lists.php.net to get a copy of this message | ||
Hi folks. I'm having a little bit of a stupid moment with a regular
expression which I'm hoping someone can lend a hand with.
The regular expression I have right now matches strings between 2 and
1000 characters in length that start with one of the following
characters:
a-z
A-Z
0-9
(
)
and where the rest of the string may be made up of the following
characters:
a-z
A-Z
0-9
(
)
_
,
.
-
'
"
Here's the working regular expresssion:
/^[a-zA-Z0-9\(\)]{1}[ a-zA-Z0-9\(\)_\,\.\-\'\"]{1,999}$/
Now, I'm trying to add \ to the valid characters but when I add a slash
after \" I get the following error:
Warning: Compilation failed: missing terminating ] for character class
at offset 54 in
/u0/vservers/*****/html/classes/forms/forms_validation_functions.class.p
hp on line 184
So I escape the \ with another \, and I still get the error.
Three or four \ results in the \ character being stripped from the
string that is being tested with the regular expression.
Five \ results in the orignal error which I get with just one \.
Can anyone give any advice as to why this is happening?
Cheers and TIA.
Pablo
/^[a-zA-Z0-9\(\)]{1}[ a-zA-Z0-9\(\)_\,\.\-\'\"]{1,999}$/