Like hippo, I don't really understand the questions(s) you're asking in the OP, and I agree with his or her recommendations here. That said, I can hazard an answer based on part of your post:

The exclusion of an entire word, not just characters ...

I think what you may be asking for is an alternative to  [^somechars] (an inverted character class) in an  [^somechars]* expression that will generalize to any pattern. Something like this may fill the bill:

c:\@Work\Perl\monks>perl -wMstrict -le "my $pattern = qr{ \b f[eio]e \b }xms; ;; my $str = 'foo bar feeble macfee unfeeling fee fumble'; ;; print qq{match: '$1'} if $str =~ m{ (bar (?: (?! $pattern) .)* f \w+) + }xms; " match: 'bar feeble macfee unfeeling fee'
The  (?: (?! $pattern) .)* sub-pattern matches "zero or more of any character so long as the character is not at the start of something matching $pattern." Contrast with the behavior of
    m{ (bar .* f \w+) }xms
(Update: Also contrast with  m{ (bar (?: (?! $pattern) .)*? f \w+) }xms (note  ? "lazy" quantifier modifier).)

Update: As a parenthetic note, the example above can be extended to show regex composition:

c:\@Work\Perl\monks>perl -wMstrict -le "my $giant_sez = qr{ \b f[eio]e \b }xms; my $not_giant = qr{ (?! $giant_sez) . }xms; ;; my $str = 'foo bar feeble macfee unfeeling fee fumble'; ;; print qq{match: '$1'} if $str =~ m{ (bar $not_giant* f \w+) }xms; " match: 'bar feeble macfee unfeeling fee'
Again, contrast with  m{ (bar $not_giant*? f \w+) }xms


Give a man a fish:  <%-{-{-{-<


In reply to Re: String replace - Part II by AnomalousMonk
in thread String replace - Part II by kepler

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.