Re: Help with preg_match and windows domain logins...

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 12/13/05, Daevid Vincent <daevid@xxxxxxxxxx> wrote:> I'm trying to do what should be a very simple regex, but can't seem to get> PHP to work, yet regex-coach and even an XML .XSD work fine:>> Valid forms of a windows logon are:> "foo\bar"> "\\foo\bar"> [...]>         //preg_match('/(\\\\)?.+(\\).+/', $logon, $matches);> [...]> Further more, WTF do I get this error:> "Compilation failed: missing ) at offset 12" (pointing to the commented out> preg_match.> WTF should adding a set of parenthesis cause a compilation error?!
WTF do you need so many WTFs?
Adding a set of parenthesis isn't causing the error. Adding anopen-bracket and then an escaped close-bracket is causing your error.The "missing ) at offset 12" is a bit of a clue there.
Backslashes are special characters to both single-quoted strings ANDregular expressions so if you use them, you're normally going to haveto escape them twice.
So if you want optional double backslashes, followed by any charactersfollowed by a backslash followed by any characters - which is what I'mguessing you were aiming at, you'd start off with this:
/^(\\)?.+\.+$/
you need to escape the backslashes for the regular expression engineso you get this:
/^(\\\\)?.+\\.+$/
and you're supplying it in a single-quoted string, which also needsthe backslashes escaped, so you get this:
'/^(\\\\\\\\)?.+\\\\.+$/'
by which point you should be swearing at Microsoft for choosing such astupid character for a login string delimiter.
Clear?
 -robin

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux