mysql request with regexs

This is a discussion on mysql request with regexs within the MySQL Database forums, part of the Database Forums category; Hi, I've got a table that contains list of url. I want a list of unique (de-duplicated) domain ...


Go Back   Usenet Forums > Database Forums > MySQL Database

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 11-09-2007
ernond_paul@yahoo.fr
 
Posts: n/a
Default mysql request with regexs

Hi,

I've got a table that contains list of url.
I want a list of unique (de-duplicated) domain name with a mysql
query. => so I want the mysql request to return only domain and not
full url

Table is like this :
name: list
columns:
- url (varchar 255)
- id (int)

row example :
url: http://groups.google.fr/group/comp.databases.mysql/post
id: 1

I've tried this :
SELECT DISTINCT(wl.url) as domain FROM list wl WHERE wl.url REGEXP
"^(.*)/.*$" GROUP BY wl.url LIMIT 0, 100

But in this example, I don't know how to get the value within the
parenthesis (in the regexp) that I would like to insert into the
distinct function => I'm searching something like :
SELECT DISTINCT($1)

Is there another way to select what I want ?
Thanks for your help

Reply With Quote
  #2 (permalink)  
Old 11-10-2007
Michael Martinek
 
Posts: n/a
Default Re: mysql request with regexs

If I recall correctly, REGEXP in MySQL is pretty weak. It will only
return 1 on match, 0 on no match.. it won't do replaces, won't return
matching segments, etc.

In situations where RegEx were needed, I always found myself writing a
PHP script to handle the RegEx portion.

Reply With Quote
  #3 (permalink)  
Old 11-10-2007
Paul Lautman
 
Posts: n/a
Default Re: mysql request with regexs

ernond_paul@yahoo.fr wrote:
> Hi,
>
> I've got a table that contains list of url.
> I want a list of unique (de-duplicated) domain name with a mysql
> query. => so I want the mysql request to return only domain and not
> full url
>
> Table is like this :
> name: list
> columns:
> - url (varchar 255)
> - id (int)
>
> row example :
> url: http://groups.google.fr/group/comp.databases.mysql/post
> id: 1
>
> I've tried this :
> SELECT DISTINCT(wl.url) as domain FROM list wl WHERE wl.url REGEXP
> "^(.*)/.*$" GROUP BY wl.url LIMIT 0, 100
>
> But in this example, I don't know how to get the value within the
> parenthesis (in the regexp) that I would like to insert into the
> distinct function => I'm searching something like :
> SELECT DISTINCT($1)
>
> Is there another way to select what I want ?
> Thanks for your help


Well, asuming that your urls all begin http://. you could do something like:

SELECT
DISTINCT LEFT(wl.url,LOCATE('/',CONCAT(wl.url,'/'),8)-1) as domain
FROM list wl WHERE wl.url REGEXP "^(.*)/.*$" GROUP BY wl.url LIMIT 0, 100


Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 09:57 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0