[regex-coach] ".+" and ".+?" with optional parenthesized text
Edi Weitz
edi at agharta.de
Sun Aug 22 13:55:09 UTC 2004
On Sun, 22 Aug 2004 14:04:47 +0100, John Clements <johnjc-regex at publicinfo.net> wrote:
> I ran the pattern with "i" checked.
I guess you also had "s" checked because your target string contained
line breaks.
> What I want it to do is match the string from the beginning through
> "between", and when there is no instance of "between", I want it to
> match the entire string.
This regex should work:
^\s*An appeal.+?(Joined )?Cases? ?t ?[-] ?\d{1,3}\/ ?\d{2}(.+?between|.*)
The behaviour you saw was right. (As a rule of thumb Regex Coach is
always right as long as it does the same as Perl... :)
You had ".+?(between)?" which meant "match as few characters as
possible up to ..." where ... was "the string 'between' OR ANYTHING"
because you made 'between' optional, i.e. you regex was equivalent to
".+?". So, the regex engine matched exactly zero characters.
Does that help?
Cheers,
Edi.
More information about the regex-coach
mailing list