Re: [PHP4BETA] preg_replace Q

From: Date: Thu, 20 Apr 2000 20:00:54 +0000
Subject: Re: [PHP4BETA] preg_replace Q
References: 1 2 3 4 5 6 7 8 9 10  Groups: php.version4 
Request: Send a blank email to php-version4+get-13833@lists.php.net to get a copy of this message
On Thu, 20 Apr 2000, Cynic wrote: > Ok, so provided I don't use any variables in the pattern I can enclose > the pattern in apostrophes, and thus use only \$. Gooooooooooood. > I will bear this in my mind. yes. > From the manual: > > The use of subpatterns for more complicated assertions is described below. > The backslashed assertions are > > \b word boundary > \B not a word boundary > > Excuse me if I'm wrong, but isn't this a bug? Or is my English so poor? > I would think that \b\$ means '$ when it's the first or the last character > in a word'. No, everything is correct. /\b\$(\w+)/ This means that you want to find $something starting at a word boundary. Since $ is a non-word character, it's considered a boundary so your example of "foo$bar" will get happily replaced. /\B\$(\w+)/ This means that $ will be in the middle of a word, so you get the results that you want. -Andrei What's hard, in hacking as in fiction, is not the writing, it's deciding what to write. -- Neal Stephenson

« previous php.version4 (#13833) next »