By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,046 Members | 2,105 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,046 IT Pros & Developers. It's quick & easy.

Substring RegExp Extract path

P: n/a
Hi,

I'm trying to extract element of a directory path stored in the db with substring

"/help/support/index/time.jsp"

and i want to extract the 1st, 2nd and 3rd parts

1st = help, 2nd = support, 3rd = index

but I can't get the regular expressions correct.

Any ideas on what I need to do.

select substring(data,'????') from paths

TIA
Nov 23 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Nick wrote:
"/help/support/index/time.jsp"

and i want to extract the 1st, 2nd and 3rd parts

1st = help, 2nd = support, 3rd = index


Are you using 7.4? If so:

select split_part('/help/support/index/time.jsp','/',2),
split_part('/help/support/index/time.jsp','/',3),
split_part('/help/support/index/time.jsp','/',4),
split_part('/help/support/index/time.jsp','/',5);
split_part | split_part | split_part | split_part
------------+------------+------------+------------
help | support | index | time.jsp
(1 row)

See:
http://www.postgresql.org/docs/curre...ns-string.html

On Postgres 8.0.0beta1 you could also do:

select s.f[2], s.f[3], s.f[4]
from (select string_to_array('/help/support/index/time.jsp','/') as f)
as s;
f | f | f
------+---------+-------
help | support | index
(1 row)

HTH,

Joe

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to ma*******@postgresql.org)

Nov 23 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.