|
View:
New views
3 Messages
—
Rating Filter:
Alert me
|
|
|
How to clean up results in Matcher Class?Hi,
I have to clear the result from the Matcher class which gets generated after =~ I have code like this... int i = 0 def sent = 'Hall Of Fame' if(sent =~ "([^\\s]+\\s[^\\s]+\\s[^\\s]+)") { /* HERE I NEED TO CLEAR THE RESULT, Which is thr in Matcher class */ sent =~ "([^\\s]+)\\s([^\\s]+)\\s([^\\s]+)" println Matcher.lastMatcher[0][1] println Matcher.lastMatcher[0][2] println Matcher.lastMatcher[0][3] } |
|
|
Re: How to clean up results in Matcher Class?You shouldn't need to clean up results (or use an if statement like that). Use the "find" method (on groovy 1.6.1 and above):
def sent = "Hall of Fame"
sent.find(/(\S+)\s(\S+)\s(\S+)/) { full, first, second, third -> println first println second println third } prints: Hall
of Fame On Thu, Jun 25, 2009 at 7:14 AM, Harsha1 <99harsha.h.n99@...> wrote:
|
|
|
Re: How to clean up results in Matcher Class?It is strange that you use lastMatcher to access the result of match. I would you like these statements:
m=sent =~ "([^\\s]+)\\s([^\\s]+)\\s([^\\s]+)"
println m[0][0]
println m[0][1]
Anyway, your program can still work only you replace sent =~ "([^\\s]+)\\s([^\\s]+)\\s([^\\s]+)" with
(sent =~ "([^\\s]+)\\s([^\\s]+)\\s([^\\s]+)") as Boolean
def sent = 'Hall Of Fame'
if(sent =~ "([^\\s]+\\s[^\\s]+\\s[^\\s]+)") { println "hello" /* HERE I NEED TO CLEAR THE RESULT, Which is thr in Matcher class */ (sent =~ "([^\\s]+)\\s([^\\s]+)\\s([^\\s]+)") as Boolean
println Matcher.lastMatcher[0][0] println Matcher.lastMatcher[0][1] println Matcher.lastMatcher[0][2] println Matcher.lastMatcher[0][3] } The reason is the lastMatcher is not saved when it is defined. It is saved when it is casted to Boolean and other a couple of situations. I don't know why.
On Thu, Jun 25, 2009 at 8:14 PM, Harsha1 <99harsha.h.n99@...> wrote:
|
| Free embeddable forum powered by Nabble | Forum Help |