|
Posted by John Dunlop on 08/04/06 14:06
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/reference.pcre.pattern.syntax.php
> These seem to contradict each other.
If they're talking about the same flavour of regex, yes.
--
Jock
Navigation:
[Reply to this message]
|