|
Posted by Miguel Cruz on 08/03/06 22:24
Marcus <JumpMan222@aol.com> wrote:
> 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
Navigation:
[Reply to this message]
|