SQLite Forum

REGEXP X{m,n} bug
Login

REGEXP X{m,n} bug

(1) By Mark Scandariato (scandariato) on 2022-07-15 15:25:25 [source]

Hello,

Using 3.39.1, I see that:

SELECT 1 WHERE 'fooX' REGEXP '^[a-z][a-z0-9]{0,30}$';  -- returns 1, not NULL
SELECT 1 WHERE 'fooX' REGEXP '^[a-z][a-z0-9]{0,30}X$'; -- returns NULL, not 1

Changing the {0,30} to {1,30} returns the expected values (while changing the minimum allowed length).

Thanks,

Mark.

(2) By Stephan Beal (stephan) on 2022-07-15 18:15:07 in reply to 1 [link] [source]

... -- returns NULL, not 1

Can you paste in the output from the sqlite3 shell? Your result is not what i'm seeing in 3.39.0 or the current /fiddle version (3.40.0, as of this writing):

$ ~/bin/sqlite3
SQLite version 3.39.0 2022-05-31 02:03:29
...
sqlite> SELECT 1 WHERE 'fooX' REGEXP '^[a-z][a-z0-9]{0,30}$';
1
sqlite> SELECT 1 WHERE 'fooX' REGEXP '^[a-z][a-z0-9]{0,30}X$';
1

(3) By jchd (jchd18) on 2022-07-15 18:57:57 in reply to 2 [link] [source]

The first example shouldn't return a match.

^ matches at start of subject:    fooX
---------------------------------^
[a-z] matches 'f':                fooX
----------------------------------^
[a-z0-9]{0,30} matches 'oo':      fooX
------------------------------------^
$ doesn't match end of subject!

Looks like [a-z] matches uppercases letters as well, as if option (?i) was in force.

(4) By Mark Scandariato (scandariato) on 2022-07-15 19:24:49 in reply to 2 [link] [source]

Doh! I apologize for the copy-paste error.

SQLite version 3.39.1 2022-07-13 19:41:41
Enter ".help" for usage hints.
Connected to a transient in-memory database.
Use ".open FILENAME" to reopen on a persistent database.
sqlite> select 1 where 'fooX' REGEXP '^[a-z][a-z0-9]{0,30}$';   -- wrong
1
sqlite> select 1 where 'fooX' REGEXP '^[a-z][a-z0-9]{0,30}X$';  -- right
1
sqlite> select 1 where 'fooX' REGEXP '^[a-z][a-z0-9_]{0,30}$';  -- wrong
1
sqlite> select 1 where 'fooX' REGEXP '^[a-z][a-z0-9_]{0,30}X$'; -- wrong
sqlite> 

(5) By jchd (jchd18) on 2022-07-15 19:53:36 in reply to 4 [link] [source]

All my use cases of SQLite have a setup where I autoload a regexp() extension based on PCRE, so I can't easily tell about the regexp engine used by sqlite3 itself.

(6) By Larry Brasfield (larrybr) on 2022-07-15 20:12:05 in reply to 4 [link] [source]

I confirm your results on trunk tip and concur with your comments re correctness. There is a problem with match count ranges.

(7) By Stephan Beal (stephan) on 2022-07-15 20:19:00 in reply to 6 [link] [source]

I confirm your results on trunk tip and concur with your comments re correctness.

@Larry, a related point for you as Docmeister:

https://www.sqlite.org/lang_expr.html

section 5 says:

No regexp() user function is defined by default and so use of the REGEXP operator will normally result in an error message.

That's apparently not the case anymore (given that that the OP and /fiddle both have regexp()), and correcting it implies documenting the flavor of regex which gets installed by default.

(8) By Mark Scandariato (scandariato) on 2022-07-15 20:29:20 in reply to 7 [link] [source]

The regexp extension from ext/misc is built into the shell - and I statically link it into my programs for use with sqlite3_auto_extension().

(9) By Larry Brasfield (larrybr) on 2022-07-15 20:29:37 in reply to 7 [link] [source]

The ext/misc/regexp.c extension is incorporated into the CLI (whether fiddle-ized or not), and is not part of the SQLite library. This shell feature is not documented. I agree that it should be. I'll see about mentioning the "bonus" extensions built into the modern CLI.

The doc fragment you cite is correct as it applies to the library rather than the CLI.