in reply to Priority of | regex operator

The (.*) is greedy. Once it captures the entire string it lets the alternation in the parens take over, which backtracks to see if it can find a match, and it can: the '...' is the first match it comes across by moving backwards.

You can use (.*?) to make the expression ungreedy and it will match what you want.

P.S. If you don't need the trailing part, use (?:) instead of ().

Replies are listed 'Best First'.
Re^2: Priority of | regex operator
by bfdi533 (Friar) on Apr 27, 2006 at 15:56 UTC

    Thank you very much for the reply. That is exactly the data that I needed to know.

    Obviously, I need to get smart of the use of the ? in a regex as I really do not understand it. But, it does work as expected now and I will hit the books or PODs and learn about that.