RC1140
RC1140

Reputation: 8663

Using mysql Regexp in a select statement not the where clause

So what i want to do is use a Regex to select only certain parts of data from a column

Example :

SELECT URL REGEXP 'http://' from websitelist --(website list is a list of URL's)

If I run that against the table it returns 1 foreach row in which 'htt://' was found, what I want is to return the string that matches the regexp

Upvotes: 2

Views: 3753

Answers (2)

Jason McCreary
Jason McCreary

Reputation: 72981

You could use just use string functions if it's as simple as your example - just removing http://

SELECT REPLACE(URL, 'http://', '') AS url FROM websitelist;

Probably faster as there is overhead for the REGEX engine.

Upvotes: 2

D.Shawley
D.Shawley

Reputation: 59563

The REGEXP operator performs a match and returns 0 or 1 based on whether the string matched the expression or not. It does not provide a way to extract the matched portion. I don't think that there is any way to extract the matched portion.

Upvotes: 2

Related Questions