Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201839

Match and replace string using REGEX in Sqlite?

$
0
0

I have a table called personal_websessions that contains data in the following format:

 id_no | website_link 
 1     | google.com 
 2     | stackoverflow.com 
 3     | msn.com 

You can create this table using the following SQL commands:

CREATE TABLE personal_websessions(id_no INTEGER PRIMARY KEY, website_link TEXT);
INSERT INTO personal_websessions VALUES(1, 'google.com'), (2, 'stackoverflow.com '), (3, 'msn.com ')

I would like to perform a find and replace using regex:

What I would like to do is if the character is 'msn.com' or 'msnnews.com etc (so something with msn in the word) in the website_link column, find that value of 'msn' and replace it with an string 'toast', but if it is not the word msn then leave it as it is. so the example above - google.com and stackoverflow.com will stay the same.

I know that the regex will be of the form (msn) as a grouping structure to match on but I do not know how to write a regex match in Sqlite.

Essentially i will have the following desired output below:

 id_no | website_link 
 1     | google.com 
 2     | stackoverflow.com 
 3     | toast

I am currently using SQlite and I know that I will have to use the REPLACE function as it is can find a pattern and then provide a replacement,

However in this link, they are not using any regex to match the words just defining them

I am really just trying to find out how to use a regex pattern to find and replace values in sqllite.

Thanks


Viewing all articles
Browse latest Browse all 201839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>