Connecting Tech Pros Worldwide Forums | Help | Site Map

preg problem

TekWiz
Guest
 
Posts: n/a
#1: Jul 17 '05
I'm using regex to validate data, but preg_match gives the Warning
"Unknown modifier '\' " when I have '\\' in the regular expression.

Is this a problem with preg_match() or do I have to do something
different with regex?

Note: I ran my expression through "The Regex Coach" by Dr. Weitz and it
worked properly.

--TekWiz

Markku Uttula
Guest
 
Posts: n/a
#2: Jul 17 '05

re: preg problem


TekWiz wrote:[color=blue]
> I'm using regex to validate data, but preg_match gives the Warning
> "Unknown modifier '\' " when I have '\\' in the regular expression.
>
> Is this a problem with preg_match() or do I have to do something
> different with regex?[/color]

I might be totally off here, but I believe that in PHP you need to
escape the backslash once for PHP and a second time for Regular
Expression.

--
Markku Uttula


Colin McKinnon
Guest
 
Posts: n/a
#3: Jul 17 '05

re: preg problem


TekWiz wrote:
[color=blue]
> I'm using regex to validate data, but preg_match gives the Warning
> "Unknown modifier '\' " when I have '\\' in the regular expression.
>[/color]
Sure your code doesn't contain "\\" ? If so then the string will be
un-escaped before the function call.

HTH

C.

TekWiz
Guest
 
Posts: n/a
#4: Jul 17 '05

re: preg problem


Here's the actual regex string that's giving me problems (it's for
validating addresses:

'/[a-zA-Z0-9\,\.\;\:\-\&\\\/\#\s\']+/'
TekWiz
Guest
 
Posts: n/a
#5: Jul 17 '05

re: preg problem



Markku Uttula wrote:[color=blue]
>
> I might be totally off here, but I believe that in PHP you need to
> escape the backslash once for PHP and a second time for Regular
> Expression.
>[/color]

Thanks, you are correct. I've got to use '\\\\' to match the '\'
character.

Many heads are better than one.

--TekWiz

Closed Thread