Jackie Jackie - 4 years ago 86
Groovy Question

groovy regex to eliminate desired character & all characters succeeding to desired character?

How to eliminate the desired character & all the other characters succeeding that desired character.

def str1 = "value_of_string*123456"


Here, desired character is
"*"
, and post desired character is
"123456"
.
So, after removing them
str1
should look like
"value_of_string"

Answer Source
def str1 = "value_of_string*123456"

assert str1.takeWhile { it != '*' } == 'value_of_string'
assert str1.tokenize('*')[0] == 'value_of_string'
assert str1.split("\\*")[0] == 'value_of_string'
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download