Thread

  1. regex Quantifiers {m,n}, m can be negative, n greater than 255

    jian he <jian.universality@gmail.com> — 2025-12-11T12:56:03Z

    hi.
    
    ""
    The forms using {...} are known as bounds. The numbers m and n within a bound
    are unsigned decimal integers with permissible values from 0 to 255 inclusive.
    ""
    Table (Regular Expression Quantifiers)
    https://www.postgresql.org/docs/current/functions-matching.html#FUNCTIONS-POSIX-REGEXP
    
    select regexp_matches(E'abc', 'a{0,257}.');
    select regexp_matches(E'abc', 'a{-0,257}.');
    select regexp_matches(E'abc', 'a{-1,2}.');
    
    based on the manual description, the second and the third query should
    error out?
    test_regex.sql (begin with line 223) have many tests but no tests for
    negative value.
    
    
    
    --
    jian
    https://www.enterprisedb.com
    
    
    
    
  2. Re: regex Quantifiers {m,n}, m can be negative, n greater than 255

    Tom Lane <tgl@sss.pgh.pa.us> — 2025-12-11T15:46:54Z

    jian he <jian.universality@gmail.com> writes:
    > select regexp_matches(E'abc', 'a{0,257}.');
    > select regexp_matches(E'abc', 'a{-0,257}.');
    > select regexp_matches(E'abc', 'a{-1,2}.');
    
    > based on the manual description, the second and the third query should
    > error out?
    
    No.  Read
    
    https://www.postgresql.org/docs/current/functions-matching.html#POSIX-ATOMS-TABLE
    
    which says that '{'
    
    	when followed by a character other than a digit, matches the
    	left-brace character {; when followed by a digit, it is the
    	beginning of a bound (see below)
    
    So your second and third patterns are just literal matches, except
    for the final '.'.
    
    You can quibble about how bright that choice was, but I think it's
    mandated by POSIX, not just something that Henry Spencer thought up.
    
    			regards, tom lane