|
Posted by FFMG on 08/15/06 07:17
Hi,
I have a bunch of strings like
$txt = 'aaa1bbbb';
Or
$txt = 'aaaaaa12bbbb';
Or
$txt = 'aaaaaa123bbb';
And I want to search and replace special cases and for unique numbers.
$txt = preg_replace( "/a{0,10}1/", "ccc", $txt );
Because I don't know the number of leading 'a' I want to use
preg_replace(...)
But with the example above 'aaaaaa12bbb' would become 'ccc2bbb' and
'aaaaaa123bbb' would become 'ccc23bbb'. That is not correct as I was
only looking for number '1'.
I want to replace exactly number '1' and not number '123' because in my
case 'aaaa1' is not the same as 'aaaa123'
So basically I need to search and replace an exact number, (because 10
is not the same as 100 for example).
How can I do that?
Many thanks.
FFMG
Navigation:
[Reply to this message]
|