jipot
jipot

Reputation: 94

Evaluating RegEx patterns within a string

I have the following code:

userInput = "develop-feature-21"
entry = "develop-feature-**"
entry = entry.replace("**", ".*");
println (userInput ==~ "$entry") // ------> false

I basically want to replace ** and add in a valid regular express .* to find all entries of develop-feature, but the problem I am having is evaluating a RegEx expression within a string.

$entry becomes develop-feature-.*, but how do I tell groovy to then evalulate .*?

Upvotes: 0

Views: 35

Answers (1)

daggett
daggett

Reputation: 28599

i've seen this in old version of groovy. i have 2.5 and your code works for me.

you could try to use

println (userInput ==~ entry)

instead of

println (userInput ==~ "$entry") 
userInput = "develop-feature-21"
entry = "develop-feature-**"
entry = entry.replace("**", ".*");
println (userInput ==~ entry) //----------> true

Upvotes: 2

Related Questions