in reply to Help please

A fairly simple regex will take care of that.

{ local $_; while (<>) { /it (.*)[.?,]$/i and print $1, $/; } }

Update: ++davidrw's points are accurate and easily corrected. I'll follow his lead and leave the modifications as an exercise. Also, you may wish to allow for any amount of any sort of whitespace after "it".

After Compline,
Zaxo

Replies are listed 'Best First'.
Re^2: Help please
by davidrw (Prior) on Jun 27, 2005 at 01:28 UTC
    Hmm.. does seem like homework as Grandfather suggested, so i won't post a regex, but instead these points for OP to consider (perldoc perlre) with regards to the above regex:
    • That will match the word "hit", and won't match "hit it." -- (hint: word boundary)
    • If there's multiple "it" words in the line, what do you want to print? (hint: greediness)
    • Should the trailing [.?,] be printed as well?
      I have searched far and wide and I can't find how to accomplish the printing of the trailing char from character set .?,
        Here's two different ways:

        One way is that you could capture the character class match with parens, and then refer to it (in this case) as $2.
        /it (.*)([.?,])$/i and print $1, $2, $/;

        Another way would be to simply move the character class to be inside the existing capturing parens:
        /it (.*[.?,])$/i and print $1, $/;
A reply falls below the community's threshold of quality. You may see it by logging in.