473,810 Members | 3,137 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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
Jul 17 '05 #1
4 1402
TekWiz wrote:
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?


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
Jul 17 '05 #2
TekWiz wrote:
I'm using regex to validate data, but preg_match gives the Warning
"Unknown modifier '\' " when I have '\\' in the regular expression.

Sure your code doesn't contain "\\" ? If so then the string will be
un-escaped before the function call.

HTH

C.

Jul 17 '05 #3
Here's the actual regex string that's giving me problems (it's for
validating addresses:

'/[a-zA-Z0-9\,\.\;\:\-\&\\\/\#\s\']+/'
Jul 17 '05 #4

Markku Uttula wrote:

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.


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

Many heads are better than one.

--TekWiz

Jul 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
8264
by: sinister | last post by:
The examples in the online manual all seem to use double quotes, e.g. at http://us3.php.net/preg_replace Why? (The behavior is different with single quotes, and presumably simpler to understand.)
2
3994
by: toedipper | last post by:
Hello, The following bit of code does a preg match and does something if true (sets $browser to ppcie) Without using if then and else's how do I code it so it does not equal what it is testing for? So if it does not find ppc in the $agent then it does something else/sets it to something else? $agent = getenv("HTTP_USER_AGENT");
4
1997
by: system7designs | last post by:
I don't know preg's that well, can anyone tell me how to write a regular expression that will select everything BUT files/folders that begin with ._ or __?(that's period-underscore and underscore underscore)
14
2025
by: frizzle | last post by:
Hi group, I have a function which validates a string using preg match. A part looks like if( !preg_match( '/^(+((*)?)?)$/', $string ) || preg_match( '/(--|__)+/' ,$string) ) { i wonder how i could combine those two into one ...
1
1967
by: terence.parker | last post by:
I am trying to do a search through some data, more specifically HTML, to extract data from it. So for example I may have: <b>Title:</b<em>This is a title</em> <b>Name:</b<em>Fred</em> I wish to grab the data "This is a title" and "Fred" against their corresponding headings in an array (e.g. $array = "This is a title") .... but the key doesn't matter, that need not come from the regexp but I can do manually.
5
1397
by: monomaniac21 | last post by:
hi all what is the preg for capitals in a word to be replaced by that word preceded by a space? i need to be able to do this in preg: thisWord := this Word AnotherExample := Another Example
3
2278
moishy
by: moishy | last post by:
If I wanted to match for instance, all characters that are not in <TAGS>, I would search for all ">ANYTHING<". But how do I make that "ANYTHING"? What will be the PREG for absolutely ANY characer? (except ">" and "<")
1
2121
by: maheswaran | last post by:
Want to replace the field D:\\Program Files\\xampp\\htdocs\\sample into D:\Program Files\xampp\htdocs\sample I tryed lot using ereg/preg replace but not suceed.....
2
4257
by: JanDoggen | last post by:
function vldLicense($lic) { echo "called with lic: ". $lic . "<br>"; echo preg_match('', $lic) . "<br>"; if (preg_match('{4}-{4}-{4}-{4}', $lic) == 0) return false; return true; } gives me:
4
3258
imarkdesigns
by: imarkdesigns | last post by:
Good day to all masters here.. good to be back here again and nice site! ok, i have a problem and still confusing to accomplish using 2 values in preg match. here is my sample code... <?php $value1 = $_POST; $value2 = $_POST;
0
9722
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10644
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10393
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9200
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7664
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5690
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4334
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3863
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3015
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.