Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Regex help
#1
Hi all, Hi Gintaras,

a little help on this one.

I have a str variable formatted as:

some text [text1] (text2) [text3] someothertext (text4)

I'd like to extract text1,text2,text3 and text4 from the the string,
BUT:

the string is not formatted exactly like that, ie the brackets and/or parenthesis pairs can have
any position and be 1 or 10 or any number

Simply, how to get ALL texts items in brackets or parenthesis in the string, whatever the number they are and their position.

Can't achieve that with findrx..

Thanks
#2
This is not perfect but worth a try...

Macro Macro17
Code:
Copy      Help
str ss s="some text [text1] (text2) [text3] someothertext (text4)"
ARRAY(str) a b
int numMatch=findrx(s "\[.*?\d+\]|\(.*?\d+\)" 0 4 a)
for int'i 0 numMatch
,ss += _s.from(a[0 i] " ")
tok(ss b)
for i 0 numMatch
,out b[i]
#3
Thanks a bunch lionking, needed some tweaking for my purpose,

but adding ? as .*? in my regex did the trick, did not rang a bell to me.

TY mate!!


Forum Jump:


Users browsing this thread: 1 Guest(s)