in reply to Prog. Perl 3rd Ed. Regex Question

You almost got the explanation right.

What the Book's RE is matching is:
Word Boundry, followed by a '1 or more character' word
Followed by space
Followed by a word-boundry
Followed by the Same word

Your RE is missing the SPACE at the end of the word found, and are trying to capture the word boundry '\b' inside the parens, which is meaningless.

"When you are faced with a dilemma, might as well make dilemmanade. "

Replies are listed 'Best First'.
Re: Re: Prog. Perl 3rd Ed. Regex Question
by makar (Novice) on Feb 13, 2004 at 05:43 UTC
    Thank you for the help. I am, however, still not sure why the \b inside the parens is meaningless.
      In the case of this particular regex, the parens are used specifically (and only) for capturing.

      \b is a zero-width assertion. It doesn't match a space, or a character of some sort. It matches when a word character is found next to a nonword character.

      Therefore, there isn't anything in particular to capture when talking about \b. So it's probably not really accurate to say that \b inside parens is meaningless, because it has just as much meaning as it would have outside the parens.

      But that's the crux of it; position inside or outside of the parens is unimportant, in this case, because the function is identical. ...the act of relocating it inside the parens is pointless, because in or out, its function is the same.

      Update: By the way, I ++ed the original question because even though it was pretty basic, it started out with "I'm sitting here reading the camel book." (paraphrasing)

      Kudos to those who do a little homework themselves and come to SoPW for clarification rather than a spoonfeeding. Very good question, in that context.


      Dave