sqlite-regex-replace-ext
sqlite-regex-replace-ext copied to clipboard
Doesn't Work
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.
sqlite> .load glib_replace.so
sqlite> select regex_replace("world", "hello, world!", "C");
hello, C!
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