[prev in list] [next in list] [prev in thread] [next in thread]
List: groovy-user
Subject: Re: [groovy-user] Switch and Regex
From: Jim White <jim () pagesmiths ! com>
Date: 2009-03-31 4:23:31
Message-ID: 49D19AC3.80006 () pagesmiths ! com
[Download RAW message or body]
switch ('abc123') {
case ~/.{10}/ : println 10 ; break
case ~/[:alpha:]+/ : println 'Word' ; break
case ~/\w{3}\d{3}/ : println 'AlphaNum' ; break
default : println 'None of the above.'
}
The test is the same as ==~ (whole string match).
Jim
Paul Bowler wrote:
>
> Hi,
>
> I need to parse incoming text messages and route the parameters to
> various services (in Grails) based upon regex patterns.
>
> Is the a standard Groovy way of combining a switch statement with Regex
> patterns?
>
> Ideally I want to traverse through a list of Regex's until a match is
> found, extract the parameters from the String and then call a service
> with those parameters.
>
> Thanks,
>
> Paul.
>
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic