Connecting Tech Pros Worldwide Help | Site Map

preg problem

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 17th, 2005, 12:14 PM
TekWiz
Guest
 
Posts: n/a
Default preg problem

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, 12:14 PM
Markku Uttula
Guest
 
Posts: n/a
Default 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, 12:14 PM
Colin McKinnon
Guest
 
Posts: n/a
Default 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, 12:14 PM
TekWiz
Guest
 
Posts: n/a
Default 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, 12:15 PM
TekWiz
Guest
 
Posts: n/a
Default 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

 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.