|
Posted by Mumia W. on 08/15/06 09:01
On 08/15/2006 02:17 AM, FFMG wrote:
> 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'
>
Perhaps use, /a{0,10}1\b/
The "\b" indicates a word boundary.
> 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.
> [...]
You're welcome.
Navigation:
[Reply to this message]
|