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. 4 2002
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
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 [].
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
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-) This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 online stuff too.
But I would like to find a mailing list or newsgroup where I can ask
questions about regexps (when things don't work), not...
|
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 variable is only
alphanumeric (no strange characters).
Here's the code:
Regex regExp = new Regex("*");
|
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 on every word ?
For example :
String myString =" This is the string that stupid H can't split up";
// A good RegEx needed here .. So the result...
|
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 string.
It's actually the input string into a Microsoft Index Server search.
The string will consist of words, perhaps enclosed in quotes or...
|
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>.
Please help
Regards
| |
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 lot of times here....
Requirement:
-------------------
I want to get the value of "href" i.e "city1.html" by searching "city1"
between the...
|
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 following:
Search a whole blob of text (including newlines and everything).
Find any text enclosed in brackets (), and replace it with a string I...
|
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 string into sets of words based on capital
letter.
For e.g. if i have a string "FirstnameLastname" I would like the result to
return me Firstname and...
|
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 regex and
the .groups method. Please help.
d|d|d|string of text 1||s|s|||dd.dd|ss|string of text
2||||||||||||||||||||||||||string of text 2
I...
|
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 an '@'in the filename on the
assumption it's already in the correct format. Uncomment the os.rename line
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
| |
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...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
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...
|
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 then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
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...
| |