|
Hi there,
I have to deal with a String and try get a number identifier out of the String after the word "Element" has occurred. Some examples I am dealing with appear as follows:
random unnecessary data Element1 random unnecessary data more random unnecessary data Element2 random unnecessary data .. more and more random unnecessary data Element57 random unnecessary data
random unnecessary data random unnecessary data Element105 more and more random unnecessary data etc So I'd like to search for "Element" and get "Element105" for example. Is there an elegant way of doing this with regular expressions in Groovy? Any help appreciated! Regards, Dave |
|
On 23 February 2012 01:16, Dave McGee <[hidden email]> wrote:
> Hi there, > > I have to deal with a String and try get a number identifier out of the > String after the word "Element" has occurred. > > Some examples I am dealing with appear as follows: > > random unnecessary data Element1 random unnecessary data > more random unnecessary data Element2 random unnecessary data > .. > more and more random unnecessary data Element57 random unnecessary data > random unnecessary data random unnecessary data Element105 more and more > random unnecessary data > > etc > > So I'd like to search for "Element" and get "Element105" for example. Is > there an elegant way of doing this with regular expressions in Groovy? def str = """ your multiline String example from above """ (str =~ /Element\d+/).each { println it } should print: Element1 Element2 Element57 Element105 If you're after number identifiers, say '2' in 'Element2', this should do the trick: (str =~ /Element(\d+)/).each { println it[1] } Cheers, Dinko > > Any help appreciated! > > Regards, > Dave --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
Woa, thanks Dinko!
On 22 February 2012 17:17, Dinko Srkoc <[hidden email]> wrote:
-- Regards, Dave |
| Powered by Nabble | See how NAML generates this page |
