Re: [PHP] (another) regex difficulty
Am Donnerstag, 02.10.03 um 01:37 Uhr schrieb Cristian Lavaque: doh, I now understand your question, you don't mean the asterisk literally, but as any character that follows a backslash... sorry -_- that's right ;) -- anyway, thanks for your effort! my problem was that i misunderstood the escape-the-meta-char-idea (see below). Am Mittwoch, 01.10.03 um 23:23 Uhr schrieb Curt Zirzow: '\\' always gets translated to '\' So the string: '/(\\)/' translates to '/(\)/' which is an invalid regex, you'll get a complaint about unclosed paren. this is also a bit tricky: echo beg \\ end\n; echo beg \ end\n; c) Why do I hate regular expressions so much? perhaps because you're using them wrong. klugscheisser ;) I've answered all 5 of em so far. thanks, your answers helped a lot! - jns -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] (another) regex difficulty
regular expressions the example below should turn any character exept \* (*= any char) into an x: $term = preg_replace('/[^(\\\)+(.){1}]/', 'x', $term); but i guess because of the [brackets] the . (period) is treated as character . instead as metacharacter (that matches any char). anyone knows how to work around this? thanks for your effort best wishes, jns ps: thanks for your help, holmes and kilimajer! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] (another) regex difficulty
* Thus wrote jonas_weber @ gmx. ch ([EMAIL PROTECTED]): regular expressions the example below should turn any character exept \* (*= any char) into an x: $term = preg_replace('/[^(\\\)+(.){1}]/', 'x', $term); preg_replace('/(?!\\).{1}/', 'x', $term); this is untested but using the assertion (?!\\), meaning that the string '\' doesn't appear before the character, should be the direction to go. see: http://php.net/manual/en/pcre.pattern.syntax.php Curt -- I used to think I was indecisive, but now I'm not so sure. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] (another) regex difficulty
From: [EMAIL PROTECTED] regular expressions the example below should turn any character exept \* (*= any char) into an x: $term = preg_replace('/[^(\\\)+(.){1}]/', 'x', $term); but i guess because of the [brackets] the . (period) is treated as character . instead as metacharacter (that matches any char). anyone knows how to work around this? Maybe... $term = preg_replace('/[^\\]./','x',$term); which would replace any character that's NOT a \ followed by any other character with an x... Not tested, of course. :) ---John Holmes... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] (another) regex difficulty
01.10.03 at 18:17 Curt Zirzow wrote: preg_replace('/(?!\\).{1}/', 'x', $term); 01.10.03 at 18:27 CPT John W. Holmes wrote: $term = preg_replace('/[^\\]./','x',$term); they don't work (thanks anyway) it's pretty simple: i need a regex that matches any character in a string except \* (* stands for any char that follows the \). example: this is \ba test should match: this a is test isn't there a way to do this? best wishes, jns -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] (another) regex difficulty
From: [EMAIL PROTECTED] it's pretty simple: i need a regex that matches any character in a string except \* (* stands for any char that follows the \). example: this is \ba test should match: this a is test isn't there a way to do this? Turn that around. What you need to do is remove \* from your string... $new_str = preg_replace('/\\./','',$old_str); Regular expressions are for pattern matching... not matching everything BUT a pattern. ---John Holmes... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] (another) regex difficulty
* Thus wrote jonas_weber @ gmx. ch ([EMAIL PROTECTED]): 01.10.03 at 18:17 Curt Zirzow wrote: preg_replace('/(?!\\).{1}/', 'x', $term); 01.10.03 at 18:27 CPT John W. Holmes wrote: $term = preg_replace('/[^\\]./','x',$term); they don't work (thanks anyway) quote orignal message the example below should turn any character exept \* (*= any char) into an x: /quote Besides that all mine needed was a extra \ $term = 'char \not xed'; preg_replace('/(?!\\\).{1}/', 'x', $term); result: xxnx will replace anychar that isnt escaped by \ to an x, with the side effect that the \ gets x'd too, thus preg_replace('/(?!\\\)[\\\]{1}/', 'x', $term); Finally fixes the problem: result: x\nx it's pretty simple: i need a regex that matches any character in a string except \* (* stands for any char that follows the \). example: this is \ba test should match: this a is test isn't there a way to do this? This is completly different problem. It isn't a matching issue but a replacement issue. preg_replace('/\\\.{1}/', '', $term); You want to remove all \* characters. Curt -- I used to think I was indecisive, but now I'm not so sure. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php