Re: regex help wanted - Mailing list pgsql-general

From Tom Lane
Subject Re: regex help wanted
Date
Msg-id 24060.1366901995@sss.pgh.pa.us
Whole thread Raw
In response to Re: regex help wanted  (Karsten Hilbert <Karsten.Hilbert@gmx.net>)
List pgsql-general
Karsten Hilbert <Karsten.Hilbert@gmx.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


pgsql-general by date:

Previous
From: Karsten Hilbert
Date:
Subject: Re: regex help wanted
Next
From: "Greg Sabino Mullane"
Date:
Subject: Re: session_replication_role `replica` behavior