Unix Technical Forum

partial string extraction with sql using regexp ?

This is a discussion on partial string extraction with sql using regexp ? within the MySQL General forum forums, part of the MySQL category; --> hi all, Here's a nut to crack: I would like to extract a part of a string stored in ...


Go Back   Unix Technical Forum > Database Server Software > MySQL > MySQL General forum

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-28-2008, 06:37 AM
Christian Hansel
 
Posts: n/a
Default partial string extraction with sql using regexp ?

hi all,

Here's a nut to crack:

I would like to extract a part of a string stored in a varchar column in a
mysql table.

Since the part of string I want to extract is neither at a fixed position
nor logically separated by a fixed character I was thinking using regexp
would by a good idea

Sample data:
alf eats 2 cats
peter's 50 cards
apple ibook 2345 sold by apple computers
scandlines mariner vessel 345 operated by Nordic Transport

(all these are made up)

What I want to extract is the part of string that is the part that comes
before the first digit ...

using perl i would :

if ($string =~ /^(.*)\d+/) {$wanted = $1;}

now my question :

if testing in sql for :
* * * * column1 regexp '([[:alpha:]]+)[[:digit:]]+([[:alpha:]]+)'
how then can I extract / refer to the first subpattern ([[:alpha:]]+) ?

What I would want is something like (what obviously doesnt work since @1 is
not set):

select
* * * * if (
* * * * * * * * column1 regexp '([[:alpha:]]+)[[:digit:]]+([[:alpha:]]+)',
* * * * * * * * @1,
* * * * * * * * column1
* * * * ) * * *
*

Besides I m running Mysql 5.0.23

Any suggestios welcome
TIA

CVH
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
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 On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 02:29 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com