Reputation: 379
Need to extract only (Sev-1) or (Sev-2) from the following strings using a regexp which suits both
1) Sev-1 (Medium)
2) Sev-2 (Medim/minor)
Upvotes: 1
Views: 6891
Reputation: 9868
Hope this is what you are looking for:
def matches = """
1) Sev-1 (Medium)
2) Sev-2 (Medim/minor)
"""=~/(Sev-\d*)/
println matches[0][1]
println matches[1][1]
this prints:
Sev-1
Sev-2
UPDATE:
okay, still the regex remains the same:
lets say your string is s
:
def matches = s =~/(Sev-\d*)/
println matches[0][1]
You may try both values in s
Upvotes: 3