10-31-2008, 10:55 PM
Hi,
I am trying to do something which I think should be relatively simple in RegEx (I know, I know...nothing is simple in RegEx ...but it's like magic when it does work!)
Anyway here is an abstract example of the problem: how to get only the first submatch
Macro
The result is
when I want it to be only the first instance ie.
I tried making "dog" to "dog" a submatch and then requesting the first submatch (from help file: A captured subpattern is the part of pattern that is enclosed in parentheses and does not begin with ?.) , but it didn't work
Macro
or
Macro
but neither worked i.e. got the whole thing again.
I also tried making result an ARRAY(str) but with less luck.
Thanks so much for any insight.
Stuart
I am trying to do something which I think should be relatively simple in RegEx (I know, I know...nothing is simple in RegEx ...but it's like magic when it does work!)
Anyway here is an abstract example of the problem: how to get only the first submatch
Macro
str sample = "There was this dog who met another dog in the dog park then ran to another dog park and then left to meet another dog"
str result
findrx(sample "((?<=dog).+(?=dog))" 0 0 result)
out result
The result is
Quote:who met another dog in the dog park then ran to another dog park and then left to meet another
when I want it to be only the first instance ie.
Quote:who met another
I tried making "dog" to "dog" a submatch and then requesting the first submatch (from help file: A captured subpattern is the part of pattern that is enclosed in parentheses and does not begin with ?.) , but it didn't work
Macro
str sample = "There was this dog who met another dog in the dog park then ran to another dog park and then left to meet another dog"
str result
findrx(sample "(dog.+dog)" 0 0 result 1)
out result
or
Macro
str sample = "There was this dog who met another dog in the dog park then ran to another dog park and then left to meet another dog"
str result
findrx(sample "((?<=dog).+(?=dog))" 0 0 result 1)
out result
but neither worked i.e. got the whole thing again.
I also tried making result an ARRAY(str) but with less luck.
Thanks so much for any insight.
Stuart