[regex-coach] ".+" and ".+?" with optional parenthesized text

Edi Weitz edi at agharta.de
Sun Aug 22 18:39:07 UTC 2004


On Sun, 22 Aug 2004 17:37:36 +0100, John Clements <johnjc-regex at publicinfo.net> wrote:

>>^\s*An appeal.+?(Joined )?Cases? ?t ?[-­] ?\d{1,3}\/ ?\d{2}(.+?between|.*)
>
> Yes, putting the ".+?" inside the parenthesis does the trick. And
> the "|.*" makes perfect sense. It says so directly "or the rest of
> the string".

What I forgot to say: Note that the order is important. This regex

  ^\s*An appeal.+?(Joined )?Cases? ?t ?[-­] ?\d{1,3}\/ ?\d{2}(.*|.+?between)

won't work because the engine will try the "rest of the string" first
and will succeed, so it will stop.

Cheers,
Edi.




More information about the regex-coach mailing list