Regex string extraction - help needed

T

TheSteph

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.
 
S

shashank kadge

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
 
?

=?ISO-8859-1?Q?G=F6ran_Andersson?=

shashank said:
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]]]]]]]".
 
S

shashank kadge

shashank said:
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
 
T

TheSteph

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]
 
L

Luc E. Mistiaen

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 said:
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 said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top