Re: RegExp - Replacing 'R&B' with 'R&&B'
| From: | Neil Freeman | Date: | Tue, 11 Jun 2002 10:52:33 +0000 |
| Subject: | Re: RegExp - Replacing 'R&B' with 'R&&B' | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-101526@lists.php.net to get a copy of this message | ||
That's perfect Michael. Thanks a lot for your help :)
Neil
Michael Weinberger wrote:
************************************************************************** This Message Was Virus Checked With : SAVI 3.58 May 2002 Last Updated 11th June 2002 ************************************************************************** $x = preg_replace( "/([^\s&])&([^\s&])/", "$1&&$2", $x ); should do the job. Michael Neil Freeman <neil.freeman@asa.co.uk> schrieb:-- ---------------------------- Work: neil.freeman@asa.co.uk Home: neil@curvedvision.com Web: www.curvedvision.com ----------------------------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