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

Regex string extraction - help needed

P: n/a
Hi,
I'm new to Regex..

Could someone show me how I can extract substring enclosed in [] ?

Example :

Source String :

"hjklhjlhjl [PARAM1] hjhlhjl [PARAM2] jsqdhjldhl"

Regex Match:

[PARAM1]

[PARAM2]

I Googeled it, found anything but that kind of extraction.

Thank-you very much for Any help !!

Steph.
Mar 9 '07 #1
Share this Question
Share on Google+
5 Replies


P: n/a
On Mar 9, 1:10 pm, "TheSteph" <TheSt...@NoSpam.comwrote:
Hi,

I'm new to Regex..

Could someone show me how I can extract substring enclosed in [] ?

Example :

Source String :

"hjklhjlhjl [PARAM1] hjhlhjl [PARAM2] jsqdhjldhl"

Regex Match:

[PARAM1]

[PARAM2]

I Googeled it, found anything but that kind of extraction.

Thank-you very much for Any help !!

Steph.
try this
\[\w*\]*

-
shashank kadge

Mar 9 '07 #2

P: n/a
shashank kadge wrote:
On Mar 9, 1:10 pm, "TheSteph" <TheSt...@NoSpam.comwrote:
>Hi,

I'm new to Regex..

Could someone show me how I can extract substring enclosed in [] ?

Example :

Source String :

"hjklhjlhjl [PARAM1] hjhlhjl [PARAM2] jsqdhjldhl"

Regex Match:

[PARAM1]

[PARAM2]

I Googeled it, found anything but that kind of extraction.

Thank-you very much for Any help !!

Steph.

try this
\[\w*\]*

-
shashank kadge
Or rather:

\[\w*\]

The extra asterisk after the bracket would make it match not only
"[anything]" but also "[anything" and "[anything]]]]]]]".

--
Göran Andersson
_____
http://www.guffa.com
Mar 9 '07 #3

P: n/a
On Mar 9, 2:03 pm, Göran Andersson <g...@guffa.comwrote:
shashank kadge wrote:
On Mar 9, 1:10 pm, "TheSteph" <TheSt...@NoSpam.comwrote:
Hi,
I'm new to Regex..
Could someone show me how I can extract substring enclosed in [] ?
Example :
Source String :
"hjklhjlhjl [PARAM1] hjhlhjl [PARAM2] jsqdhjldhl"
Regex Match:
[PARAM1]
[PARAM2]
I Googeled it, found anything but that kind of extraction.
Thank-you very much for Any help !!
Steph.
try this
\[\w*\]*
-
shashank kadge

Or rather:

\[\w*\]

The extra asterisk after the bracket would make it match not only
"[anything]" but also "[anything" and "[anything]]]]]]]".

--
Göran Andersson
_____http://www.guffa.com- Hide quoted text -

- Show quoted text -
Correct Goran.

-
shashank kadge

Mar 9 '07 #4

P: n/a
I did my homework this week-end...

I found a solution to my problem, Here it is

RegexExpression : \[[^\]|^\[]*\]

From : [111]qf fds fdsf[P-TE ST-1]dsqfdsq[123123]fdsfd sq()[]fdsqf+12589 f
fd fdsf [P-TEST-2] f fdsf dsf df[]dsfdsq[P-TEST-3]fdsqf df[[456]]

I get :
[111]
[P-TE ST-1]
[123123]
[]
[P-TEST-2]
[]
[P-TEST-3]
[456]
"TheSteph" <Th******@NoSpam.comwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
Hi,
I'm new to Regex..

Could someone show me how I can extract substring enclosed in [] ?

Example :

Source String :

"hjklhjlhjl [PARAM1] hjhlhjl [PARAM2] jsqdhjldhl"

Regex Match:

[PARAM1]

[PARAM2]

I Googeled it, found anything but that kind of extraction.

Thank-you very much for Any help !!

Steph.


Mar 12 '07 #5

P: n/a
I am not sure it does exactly what you want. It exclude the vertical bar and
the caret from allowed character between square bracket. The alternation
character is a simple normal character in a list between square bracket and
then the caret should not be repeated for exclusion. Also it follows you
don't have to quote special regex characters between square bracket.

I think you meant \[^][]*\]

/LM

"TheSteph" <Th******@NoSpam.comwrote in message
news:Oy**************@TK2MSFTNGP04.phx.gbl...
>I did my homework this week-end...

I found a solution to my problem, Here it is

RegexExpression : \[[^\]|^\[]*\]

From : [111]qf fds fdsf[P-TE ST-1]dsqfdsq[123123]fdsfd sq()[]fdsqf+12589
f
fd fdsf [P-TEST-2] f fdsf dsf df[]dsfdsq[P-TEST-3]fdsqf df[[456]]

I get :
[111]
[P-TE ST-1]
[123123]
[]
[P-TEST-2]
[]
[P-TEST-3]
[456]
"TheSteph" <Th******@NoSpam.comwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
>Hi,
I'm new to Regex..

Could someone show me how I can extract substring enclosed in [] ?

Example :

Source String :

"hjklhjlhjl [PARAM1] hjhlhjl [PARAM2] jsqdhjldhl"

Regex Match:

[PARAM1]

[PARAM2]

I Googeled it, found anything but that kind of extraction.

Thank-you very much for Any help !!

Steph.



Mar 12 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.