in reply to Defenetly a complicated perl recipie with 2 arrays, 1 scaler and some special matching

I believe that to do what you want do say, with the side effect of possibly leaving extra spaces in your topic:
{ $topic =~ s/(^|\W)$_($|\W)/$1$2/g; }

update yea yea, my original code was fscked up badly .. that's what you get for looking at what edits need to be done at the same time...

that is, look for the word between either the start of the starting or a non-word character, and either the end of the string or a non-word character. You might end up with consecutive spaces in the topic this way; you may want to consider using a placeholder to indicate you removed something (something as simple as BLEEP), but that's up to your project specifications.


Dr. Michael K. Neylon - mneylon-pm@masemware.com || "You've left the lens cap of your mind on again, Pinky" - The Brain
  • Comment on Re: Defenetly a complicated perl recipie with 2 arrays, 1 scaler and some special matching
  • Download Code

Replies are listed 'Best First'.
Re: Defenetly a complicated perl recipie with 2 arrays, 1 scaler and some special matching
by Dominus (Parson) on Jul 15, 2001 at 06:49 UTC
    Says masem:
    { $topic =~ s/([^/W])$_([$/W])/$1$2/g; }
    There are several errors here. You have /W where you seem to have meant \W. You have ^ inside a character class, where it means to negate the class, but you seem to have wanted it outside, so that it means beginning-of-string. You have $ inside the other character class, so you are interpolating $/ into the regex, and you seem to have wanted the $ in a place where it would mean end-of-string. I think you might have meant:
    s/(^|\W)$_(\W|$)/$1$2/g
    But the thing I suggested with \b is simpler anyway.

    --
    Mark Dominus
    Perl Paraphernalia

      both of those work great and are doing exactly what I need! thanks!