I've got a table with entries that are similar to "something XXX010101 somethingelse XXX010102".
I'd like to extract the XXX01... parts from them - possibly using some separator if needed - right now I'm able to easily take out the first one using:
select distinct substring(content from 'XXX[0-9]+'), content from data where content ~ 'XXX[0-9]+'
The one idea I have is to create some monster regex to replace everything that's not an XXX substring... but to be true I hoped (and failed to find) for a simpler solution (like a g flag to substring).
When looking around I found that 8.3 introduced a regex_matches function that seems to be what I'd need - are there any alternatives in 8.2? Or an easy way to get it in 8.2?
How would you go about solving this? Or is an upgrade my best bet? ;) (it's a production system so the downtime and some risk of problems after migration is a source of hesitation ).
Thanks in advance.
-- expected output added --
for
"something XXX010101 something else XXX010102"
I'd like to get:
XXX010101
XXX010102
OR (less preferable)
XXX010101,XXX010102
How about something like this (assuming the values you're looking for are contained in a separate table)... I'll make no claims as to good performance though...
let table A contain all possible combinations of XXX010101... that your looking for
let table B contain all the search texts you want
Results:
--------WRONG but misunderstood the question...
What's wrong with the replace function? http://www.postgresql.org/docs/8.2/interactive/functions-string.html
so the characters are set to empty string.