Reputation: 62
I have a string like "AAA_revision12" and I have to extract the substring before "_" for example "AAA". I tried some regexps, but they doesn't work in jenkins.
String stringParser(String inputString) {
inputString ? inputString.split(/_\d/)[0] : ''
}
$string = "AAA revision".split('-')
assert string[0]
Upvotes: 1
Views: 6936
Reputation: 340
Your question is very confusing. I presume you are after a groovy snippet which will return the substring. If so:
String stringParser(String inputString) {
inputString.split("_")[0]
}
As an example:
String input = "foo_bar"
desired = "foo"
assert desired == stringParser(input)
> True
Upvotes: 4