« Return to Thread: How to clean up results in Matcher Class?

Re: How to clean up results in Matcher Class?

by edmund zheng :: Rate this Message:

Reply to Author | View in Thread

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:

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]
               }
--
View this message in context: http://www.nabble.com/How-to-clean-up-results-in-Matcher-Class--tp24202110p24202110.html
Sent from the groovy - user mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

   http://xircles.codehaus.org/manage_email



 « Return to Thread: How to clean up results in Matcher Class?