473,387 Members | 3,033 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Substring RegExp Extract path

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
1 5675
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Tim Smith | last post by:
I am looking to extract form element values from html, more generally I have a substring that identifies the beginning of a value and a string that identifies the end of value and I need to extract...
4
by: - | last post by:
i have a column "path" with values eg. +---------------+ | path | +---------------+ |/path/path/path| +---------------+ |/path/path | +---------------+ |/path |
1
by: geos | last post by:
hello, I have the problem writing the regular expression to verify the valid system path in the way that RegExp.$1 has to contain path up to the parent folder of a file, and RegExp.$2 should...
6
by: joseph speigle | last post by:
hi, Does anybody know offhand what is the correct way to use substr to extract the domain name from a client_referer column as logged by mod_pgsqllog (httpd module), by correcting the following: ...
2
by: Badass Scotsman | last post by:
Hello, Using VB and ASP,NET I would like to be able to search a STRING for a smaller STRING within, based on the characters which appear before and after. For example: String1 = " That was...
0
by: Nico Grubert | last post by:
Hi there, in a text with no carriage returns I need to look for all occurancies of this string: <source id="box"><parameter key="path">...</parameter></source> The ... can contain different...
4
by: Jean-François Michaud | last post by:
Hello, I've been looking at this for a bit now and I don't see what's wrong with the code. Can anybody see a problem with this? Here is an XSLT snippet I use. <xsl:template match="graphic">...
11
by: dyc | last post by:
how do i make use of substring method in order to extract the specified data from a a long string? I also need to do some checking b4 extracting the data, for instance: it only will extract the...
1
by: Alberto Sartori | last post by:
Hello, I have a html text with custom tags which looks like html comment, such: "text text text <p>text</ptext test test text text text <p>text</ptext test test <!-- @MyTag@ -->extract...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.