in reply to Matching 'words' in a string based on a suffix

The regexp you are looking for is:

~s/\w+ing\b/pudding/g

for which japhy's YAPE::Regexp-Explain] gives the following explanation (reformated):

The regular expression: /\w+ing\b/ matches as follows: NODE EXPLANATION ==== =========== \w+ word characters (a-z, A-Z, 0-9, _) (1 or more times) ing 'ing' \b the boundary between a word char (\w) and something that is not a word char

If you want strings like f***ing to be replaced use \S (matches anything but a space) instead of \W.

Your regexp does not compile, I guess you wanted to write something like /\S+ing/ which matches anything that's not spaces then ing but then strings like derringer (ing in the middle of the string) would be matched.

Replies are listed 'Best First'.
Re: Re: Matching 'words' in a string based on a suffix
by magnus (Pilgrim) on Feb 07, 2001 at 15:52 UTC
    it's true that the expression  /\S+ing/ would match  derringer
    but  /\S+ing$/ wouldn't...

    this expression would also work in the above required example, i believe...
      mirod just pointed out, the  $ in my previous reply should have been a  \b... thanks, mirod...