Connecting Tech Pros Worldwide Help | Site Map

preg problem

  #1  
Old July 17th, 2005, 01:14 PM
TekWiz
Guest
 
Posts: n/a
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
  #2  
Old July 17th, 2005, 01:14 PM
Markku Uttula
Guest
 
Posts: n/a

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


  #3  
Old July 17th, 2005, 01:14 PM
Colin McKinnon
Guest
 
Posts: n/a

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.

  #4  
Old July 17th, 2005, 01:14 PM
TekWiz
Guest
 
Posts: n/a

re: preg problem


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

'/[a-zA-Z0-9\,\.\;\:\-\&\\\/\#\s\']+/'
  #5  
Old July 17th, 2005, 01:15 PM
TekWiz
Guest
 
Posts: n/a

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Value of 2 fields in 1 preg match imarkdesigns answers 4 December 14th, 2008 04:27 AM
PREG search for multiple values in one pass? terence.parker@gmail.com answers 1 August 19th, 2006 09:45 AM
eregi or similar_text < -- problem either way george answers 5 July 17th, 2005 05:01 AM
simple regex problem Chamomile answers 5 July 17th, 2005 04:01 AM