Re: (another) regex difficulty

From: Date: Wed, 01 Oct 2003 21:15:25 +0000
Subject: Re: (another) regex difficulty
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-164631@lists.php.net to get a copy of this message
* Thus wrote jonas_weber @ gmx. ch (jonas_weber@gmx.ch): > 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: xxxxxxnxxxxx 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: xxxxx\nxxxxx > > 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."

« previous php.general (#164631) next »