-2
def testString = '''
relkey = CAT_RELEASE_AUG_2018
relkey2 = CAT_RELEASE_SEP_2019
'''

using groovy - how can i get both the relkey and relkey2 values - Thanks

garlapak
  • 2,309
  • 3
  • 14
  • 12
  • 3
    Possible duplicate of [extract substring using regex in groovy](https://stackoverflow.com/questions/17536921/extract-substring-using-regex-in-groovy) – ernest_k Feb 07 '19 at 11:11
  • Can I have the example please as I have multiple releases keys - thanks – garlapak Feb 07 '19 at 12:08
  • You should not to store it like this, that's the first point I want to mention, better will be use eg. `Map` for key-value pairs, or, at least you should to use eg. String array.. Then you will be able to iterate over each element of the object make split or substring of these specific strings – xxxvodnikxxx Feb 07 '19 at 13:16
  • can i have the example please. Thanks – garlapak Feb 07 '19 at 13:17

1 Answers1

3

Method 1:

String val = testString.substring(testString.indexOf("=")+1)

For more options, you can use this too.

Method 2:

String val = testString.split("=")[1]

But it is up to you.

For example to load as map: There are many methods to load as map but for simple example,

String a= "h=1"
Map kv=[:]
List b = a.split("="); 
kv[b[0]]=b[1] 
println kv
Bhanuchander Udhayakumar
  • 1,581
  • 1
  • 12
  • 30