Groovy - Extract and display a substring from a String -



Groovy - Extract and display a substring from a String -

i find pattern below string. words containing "match.text3", perchance latest 1 matching ending number.

{match.text1.1=[1, admin, 07/10/14 09:29:34], match.text2.2=[2, admin, 07/10/14 10:01:08], match.text3.3=[3, admin, 07/10/14 10:08:01], match.text3.4=[4, admin, 07/10/14 11:08:01], match=[text3]}

expected output:

match.text3.4 or match.text3.3 match.text3.4

you can utilize findall() method on string extract tokens match given pattern:

string s = '{match.text1.1=[1, admin, 07/10/14 09:29:34], match.text2.2=[2, admin, 07/10/14 10:01:08], match.text3.3=[3, admin, 07/10/14 10:08:01], match.text3.4=[4, admin, 07/10/14 11:08:01], match=[text3]}' list<string> tokens = s.findall(/match\.text3(\.[0-9]+)?/) assert tokens == ['match.text3.3', 'match.text3.4'] string lastly = tokens.last() assert lastly == 'match.text3.4'

groovy

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -