nalgeon / sqlean

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

Problem with regexp_replace #75

Closed antarey closed 1 year ago

antarey commented 1 year ago

There is a sqlite table

CREATE TABLE IF NOT EXISTS extention_files_detal (
    source_path    TEXT,
    source_text    BLOB,
    extention_type INTEGER,
    condition      TEXT,
    id             INTEGER PRIMARY KEY ON CONFLICT ROLLBACK AUTOINCREMENT
);

INSERT INTO extention_files_detal (
                                      source_path,
                                      source_text,
                                      extention_type,
                                      condition,
                                      id
                                  )
                                  VALUES (
                                      '{SYSTEMNAME_ALL_LOWER}.xml',
                                      '<?xml version=''1.0'' encoding=''utf-8''?>
<extension type="component" method="upgrade">
...
        -cbAddDBTable{<folder>language</folder>}-
....
</extension>
',
                                      NULL,
                                      NULL,
                                      1
                                  );

Query select regexp_replace(ed.source_text, '(-cbAddDBTable{)([\s\S]*?)(}-)', '%2') from extention_files_detal ed return

<?xml version='1.0' encoding='utf-8'?>
<extension type=""component"" method=""upgrade"">
...
        %2
....
</extension>

but should return

<?xml version='1.0' encoding='utf-8'?>
<extension type=""component"" method=""upgrade"">
...
       <folder>language</folder>
....
</extension>

thanks for the help

nalgeon commented 1 year ago

The replacement expression should be $2, not %2.

antarey commented 1 year ago

Sorry