Re: regex help wanted

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Karsten Hilbert <Karsten(dot)Hilbert(at)gmx(dot)net>
Cc: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: regex help wanted
Date: 2013-04-25 14:59:55
Message-ID: 24060.1366901995@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Karsten Hilbert <Karsten(dot)Hilbert(at)gmx(dot)net> writes:
> I would have thought "<[^<]+?:" should mean:

> match a "<"
> followed by 1-n characters as long as they are not "<"
> until the VERY NEXT ":"

> The "?" should make the "+" after "[^<]" non-greedy and thus
> stop at the first occurrence of ":", right ? Or am I
> misunderstanding that part ?

No, non-greedy just means that if there are multiple ways to make the
pattern match the string, prefer the way that makes this sub-match the
shortest (whereas the default makes leftmost sub-matches longest).
If you don't want the char class to match : then you need to say that
explicitly.

BTW, I'm fairly sure that unless you are doing something that extracts
or replaces sub-matches, there is no value whatever in marking
quantifiers non-greedy; that just complicates life for the regex
compiler. A match is a match, if you're not paying attention to
where the subpattern boundaries are.

regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Greg Sabino Mullane 2013-04-25 15:49:55 Re: session_replication_role `replica` behavior
Previous Message Karsten Hilbert 2013-04-25 14:46:12 Re: regex help wanted