Regex - how to match until something
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.php archive

Regex - how to match until something

From: <veg_all@yahoo.com>
Date: Sat Apr 29 2006 - 22:46:31 CEST

How do you replace an occurence until a certain point: You can see my
example code below and the output:

$string1 = 'Hello world today';
$string2 = 'Hello blahblah';

$string1 = preg_replace ( '/Hello.*(?!today)/', 'Hello ***' , $string1
);
$string2 = preg_replace ( '/Hello.*(?!today)/', 'Hello ***' , $string2
);

echo "$string1 - This should be Hello *** today\n";
echo "$string2 - This is correct\n";

Outputs:
======
Hello *** - This should be Hello *** today
Hello *** - This is correct
Received on Mon May 1 03:07:33 2006