Re: RegExp - Replacing 'R&B' with 'R&&B'
| From: | Michael Weinberger | Date: | Tue, 11 Jun 2002 10:29:33 +0000 |
| Subject: | Re: RegExp - Replacing 'R&B' with 'R&&B' | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-101523@lists.php.net to get a copy of this message | ||
$x = preg_replace( "/([^\s&])&([^\s&])/", "$1&&$2", $x );
should do the job.
Michael
Neil Freeman <neil.freeman@asa.co.uk> schrieb:
> Hi,
>
> For all you Unix gurus this should be run of the mill stuff but us
> Windows boys tend to get confused easily :)
>
> How can I easily match occurrences of text along the lines of R&B and
> replace it with R&&B ?
>
> The regular expression s/&/&&/g obviously replaces any occurrence of an
> ampersand with a double ampersand but I need to do a match so that it
> only replaces instances which have non whitespace on either side of it,
> ie \S&\S
>
> I think I'm along the right lines but haven't had enough experience with
> regular expressions yet to 'finish the job'.
>
> Hope you can help.
>
> Neil
>
> --
> ----------------------------
> Work: neil.freeman@asa.co.uk
> Home: neil@curvedvision.com
>
> Web: www.curvedvision.com
> ----------------------------
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>