dancow
dancow

Reputation: 3388

How to use REGEXP in SQLite3 to extract matched string (as a column value)

Is there a way to use REGEXP to return not just whether or not there was a match (i.e. 1 or 0), but the actual match itself. For example, if I have a column of URLs and I want to extract the matched portion of a URL (e.g. the domain):

SELECT url REGEXP '\w+\.com' AS domain
FROM urls
GROUP by domain;

Not sure if there are differences between REGEXP extensions, but FWIW, I'm using the one found in DB Browser for SQLite

Upvotes: 2

Views: 7318

Answers (1)

CL.
CL.

Reputation: 180080

The REGEXP operator returns just a boolean value, whether the text matches or not.

If you want to get more information, you have to write some other function.

Upvotes: 3

Related Questions