in reply to Re: Regular Expression To Extract Multiple Matches Pattern
in thread Regular Expression To Extract Multiple Matches Pattern

Original Post:

I was working on a regular expression today to extract phrases like "not-too-shabby" and "never-before-seen",. that is, three words separated by hyphens

The original post does talk about 'extracting' not 'replacing'. And something like print $1; always raises a red flag for me -- you usually want print "$1\n"; instead, otherwise the doubly hyphenated words that the script has found will run into each other -- probably not what you want.

--t. alex

"Excellent. Release the hounds." -- Monty Burns.

Replies are listed 'Best First'.
Re: Re: Re: Regular Expression To Extract Multiple Matches Pattern
by Kanji (Parson) on Jan 07, 2002 at 20:15 UTC

    Further on down in the post, Cody says ...

    ...but surely there's a smarter way to do it than check there's a match, then extract it with one regex, then remove it from the test string with another?

    Perhaps I'm reading the bolded part of that wrong, but it sounds like replacing to me; a notion reinforced by the code snippet given.

    The $1 was an oversight, though: an artifact of using -l in my shebang. ;)

        --k.


      Hi, thank you all for your help.

      The regex I put in there is not exactly the regex I used, as I said, the regex was not the point of the exercise.

      It all seems so simple now that I know I can do a "while" like that.