473,473 Members | 2,002 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

help with regex

Hello,

I am trying to include the literal '\' (backslash) character in a regex.
I am not sure if I need to escape it, however...

From http://www.regular-expressions.info/charclass.html:
"To include a backslash as a character without any special meaning
inside a character class, you have to escape it with another backslash.
[\\x] matches a backslash or an x."

From http://www.tin.org/bin/man.cgi?section=7&topic=regex:
"...all other special characters, including `\', lose their special
significance within a bracket expression."

These seem to contradict each other. Both ways *seem* to work, but I am
not familiar enough with regex's to know if one is producing some other
side effect that I am not aware of. Thanks a bunch for your help.
Aug 3 '06 #1
4 1995
Marcus <Ju********@aol.comwrote:
I am trying to include the literal '\' (backslash) character in a regex.
I am not sure if I need to escape it, however...

From http://www.regular-expressions.info/charclass.html:
"To include a backslash as a character without any special meaning
inside a character class, you have to escape it with another backslash.
[\\x] matches a backslash or an x."

From http://www.tin.org/bin/man.cgi?section=7&topic=regex:
"...all other special characters, including `\', lose their special
significance within a bracket expression."

These seem to contradict each other. Both ways *seem* to work, but I am
not familiar enough with regex's to know if one is producing some other
side effect that I am not aware of. Thanks a bunch for your help.
I don't see the contradiction. What specifically do you find to be
contradictory there? Backslash loses its special significance inside
brackets, but you do need to escape it. Whenever you are referring to a
literal backslash in a regex, put \\ instead. Simple as that.

If you're still having problems, why not post your regex?

miguel
--
Photos from 40 countries on 5 continents: http://travel.u.nu
Latest photos: Malaysia; Thailand; Singapore; Spain; Morocco
Airports of the world: http://airport.u.nu
Aug 3 '06 #2
Miguel Cruz wrote:
Backslash loses its special significance inside
brackets, but you do need to escape it.
My confusion came from the fact that I was interpreting this statement
to mean that by losing its "special significance" (escape character), it
was just treated as a literal character when inside [].
Aug 3 '06 #3
Marcus:
I am trying to include the literal '\' (backslash) character in a regex.
>From the beginning. What planet are you on? What country? Town?
System? PHP version? Regex flavour?
I am not sure if I need to escape it, however...

From http://www.regular-expressions.info/charclass.html:
"To include a backslash as a character without any special meaning
inside a character class, you have to escape it with another backslash.
[\\x] matches a backslash or an x."

From http://www.tin.org/bin/man.cgi?section=7&topic=regex:
"...all other special characters, including `\', lose their special
significance within a bracket expression."
The first is talking about regexes in general, the second about POSIX
regexes.

Take it from the horse's mouth: 'All non-alphanumeric characters other
than \, -, ^ (at the start) and the terminating ] are non-special in
character classes, but it does no harm if they are escaped.'.

http://www.php.net/manual/en/referen...ern.syntax.php
These seem to contradict each other.
If they're talking about the same flavour of regex, yes.

--
Jock

Aug 4 '06 #4
John Dunlop wrote:
Marcus:
>I am trying to include the literal '\' (backslash) character in a regex.
>>From the beginning. What planet are you on? What country? Town?
System? PHP version? Regex flavour?
> I am not sure if I need to escape it, however...

From http://www.regular-expressions.info/charclass.html:
"To include a backslash as a character without any special meaning
inside a character class, you have to escape it with another backslash.
[\\x] matches a backslash or an x."

From http://www.tin.org/bin/man.cgi?section=7&topic=regex:
"...all other special characters, including `\', lose their special
significance within a bracket expression."

The first is talking about regexes in general, the second about POSIX
regexes.

Take it from the horse's mouth: 'All non-alphanumeric characters other
than \, -, ^ (at the start) and the terminating ] are non-special in
character classes, but it does no harm if they are escaped.'.

http://www.php.net/manual/en/referen...ern.syntax.php
>These seem to contradict each other.

If they're talking about the same flavour of regex, yes.
I am new to PHP but I just saw a free tool for building pcre patterns.
http://www.waterproof.fr/products/RegExpEditor
Thanks in Advance...
IchBin, Pocono Lake, Pa, USA http://weconsultants.phpnet.us
__________________________________________________ ________________________

'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor, Regular Guy (1952-)
Aug 4 '06 #5

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

Similar topics

6
by: Tony C | last post by:
I'm writing a python program which uses regular expressions, but I'm totally new to regexps. I've got Kuchling's "Regexp HOWTO", "Mastering Regular Expresions" by Oreilly, and have access to...
8
by: Bibe | last post by:
I've been trying to get this going for awhile now, and need help. I've done a regex object, and when I use IsMatch, it's behavior is quite weird. I am trying to use Regex to make sure that a...
4
by: H | last post by:
This is kind of an followup on oneof my previous questions, and it has with RegEx to do. I have a string containing of several words. What would a good regex expression looklike to get one match...
6
by: Dave | last post by:
I'm struggling with something that should be fairly simple. I just don't know the regext syntax very well, unfortunately. I'd like to parse words out of what is basically a boolean search...
4
by: henrik | last post by:
Hi I have a regex question. I want to find all content of a <td class="someclass"> tag. This means the expression should include all other tags included between <td class="someclass"> and </td>....
9
by: jmchadha | last post by:
I have got the following html: "something in html ... etc.. city1... etc... <a class="font1" href="city1.html" onclick="etc."click for <b>info</bon city1 </a> ... some html. city1.. can repeat...
2
by: Alex Maghen | last post by:
This is a bit of an abuse of this group. Just a nit, but I'm hoping someone really good with Regular Expressions can help me out here. I need to write a regular expression that will do the...
3
by: =?Utf-8?B?TmF2ZWVu?= | last post by:
Not sure if this is the right forum for this question but couldn'd find another newsgroup. I am new to Regular expressions and would like help in deciding which pattern allows me to split a...
10
by: supercrossking | last post by:
I am trying to the values of string of text in the sample before. The ds are for digits and s is for string and string of text is for a string with more than one or two values. I am trying to use...
0
by: Support Desk | last post by:
That’s it exactly..thx -----Original Message----- From: Reedick, Andrew Sent: Tuesday, June 03, 2008 9:26 AM To: Support Desk Subject: RE: regex help The regex will now skip anything with...
0
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,...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...
1
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.