asg017 / sqlite-regex

A fast regular expression SQLite extension, written in Rust
Apache License 2.0
166 stars 7 forks source link

Support for flags #13

Open titanism opened 10 months ago

titanism commented 10 months ago

There's a comment here but it seems unrelated to the code https://github.com/asg017/sqlite-regex/blob/5fe28e3c7a978c621082cfef0ae6dea9a71167ee/src/regex.rs#L10-L11. Does this lib support flags? (e.g. i)

titanism commented 10 months ago

Looks like we can set it such as REGEXP '(?i)LINUS with (?i) in the regex itself, e.g. to match linus, Linus, LINUS, etc. Having a flag would be great too somehow (?)

asg017 commented 10 months ago

Yeah, the (?i) syntax is the current way to define flags, like:

select 
  value, 
  value regexp '(?i)linus' ,
  value regexp 'linus'
from json_each('["linus", "Linus", "LINUS", "moo"]');

/*
┌───────┬──────────────────────────┬──────────────────────┐
│ value │ value regexp '(?i)linus' │ value regexp 'linus' │
├───────┼──────────────────────────┼──────────────────────┤
│ linus │ 1                        │ 1                    │
│ Linus │ 1                        │ 0                    │
│ LINUS │ 1                        │ 0                    │
│ moo   │ 0                        │ 0                    │
└───────┴──────────────────────────┴──────────────────────┘
*/

The underlying Rust regex crate doesn't offer a way to define flags in any other way. I may also add a new regexpi() function that'll implicitly add the ignore flag in the next reelase.