nalgeon / sqlean

The ultimate set of SQLite extensions
MIT License
3.65k stars 115 forks source link

Problem with regex_replace #123

Closed paul1149 closed 2 months ago

paul1149 commented 2 months ago

Hi, I'm using the latest sqlean regexp.so in the latest DB Browser for SQLite. I'm trying to update a table using the following query:

UPDATE content SET data = regexp_replace ( data , '\\sl300' , '\sl290' ) ;

No error is reported, but nothing is done. However, if I run the same command searching for a literal, it works:

UPDATE content SET data = regexp_replace ( data , 'DejaVu Sans' , 'Open Sans' ) ;

So it seems I'm running a search without benefit of the regex function.

And yet if I run the first search without escaping the backslash in the FIND argument:

UPDATE content SET data = regexp_replace ( data , '**\sl300'** , '\sl290' ) ;

Nothing is changed there either.

Typical text that I'm trying to hit looks like:

\pard\sl300\fi0\li0\tx705

I'm sure I'm creating the problem here, but I don't know where it is. Thanks.

nalgeon commented 2 months ago

The correct query would be:

update content set data = regexp_replace(data, '\\sl300', '\\sl290');

Using your example:

select regexp_replace('\pard\sl300\fi0\li0\tx705', '\\sl300', '\\sl290');
-- \pard\sl290\fi0\li0\tx705
paul1149 commented 2 months ago

Thanks so much for that. I missed that the replacement also needed escaping. Much appreciated. :)

nalgeon commented 2 months ago

Sure!