Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doesn't Work #1

Open
rothkj1022 opened this issue Jun 23, 2017 · 2 comments
Open

Doesn't Work #1

rothkj1022 opened this issue Jun 23, 2017 · 2 comments

Comments

@rothkj1022
Copy link

Was able to compile and load extension to sqlite db, but the regex_replace() function just doesn't work. Seems to always return the second parameter.

Perhaps providing some usage examples and/or instructions would help.

@gwenn
Copy link
Owner

gwenn commented Jun 29, 2017

sqlite> .load glib_replace.so
sqlite> select regex_replace("world", "hello, world!", "C");
hello, C!

@gsker
Copy link
Contributor

gsker commented Feb 6, 2021

I too would like to see some examples. And a description.
I've been using this function for a while with this module and never looked very closely.
But it looks like its arguments are in a different order from Oracle and MySQL.
mysql has args of expression (the field name), pat (the regex), replacement.
But this one is pattern, expression, replacement.
From the source code:

    const UChar *zPattern = sqlite3_value_text16(argv[0]);
    const UChar *zString = sqlite3_value_text16(argv[1]);
    const UChar *zReplacement = sqlite3_value_text16(argv[2]);
sqlite> CREATE TABLE test(name CHAR);
sqlite> INSERT INTO test VALUES ("alphabetical");
sqlite> SELECT * FROM test ;
alphabetical
sqlite> SELECT name,regex_replace("p.*i",name,"junk")  FROM test;
alphabetical|aljunkcal
And more:
sqlite> INSERT INTO test VALUES ("anti-alphabetical");
sqlite> SELECT 
              name,
               REGEX_REPLACE("p.*i",name,"junk"),
               REGEX_REPLACE("^a.*?i",name,"betterjunk") 
           FROM test;

alphabetical|aljunkcal|betterjunkcal
anti-alphabetical|anti-aljunkcal|betterjunk-alphabetical

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants