In short summary, rather than quoting, the regex so far suggested has been:

s/([^a-zA-Z]*)Booty([^a-zA-Z]*)/\1_Booty_\2/

This should work AFAIK, but this should also work and IMO a little more flexible:

s/(?<![a-zA-Z])Booty(?![a-zA-Z])/_Booty_/

Now I don't know about PHP in particular, I've only had experience with regexes in Perl, but AFAIK this is a standard POSIX regex thing (not perl specific). "(?<!pattern1)pattern2" does a negative look-behind (prematch) so it matches pattern2 as long as it's not preceded by pattern1 (the positive look-behind, to match pattern2 preceded by pattern1, is "(?<=pattern1)pattern2"). "pattern1(?!pattern2)" is the same thing, but look-ahead (post-match). It's positive version is "pattern1(?=pattern2)". The advantage is that nothing has to be captured, and if you want to use the prematch/match/postmatch variables set by evaluating the expression (in perl they're $`, $& and $', respectively) the match variable for something like "Trash some Booty.\n" is just "Booty", not " Booty.\n"

Jacob Fugal


____________________
BYU Unix Users Group http://uug.byu.edu/ ___________________________________________________________________
List Info: http://uug.byu.edu/cgi-bin/mailman/listinfo/uug-list

Reply via email to