How to make REGEX (Groovy) to select the words "She", "Shell" with REGEX = "She"?

I am new to REGEX, I am trying to get only the words "She" and "Shell", not the ashes with this program (Groovy). I have been working on it for some time.

saying = 'She wishes for Shells not ashes'
println saying
def pattern = ~/\bShe*\b/
def matcher = pattern.matcher(saying)
def count = matcher.getCount()
println "Matches = ${count}"
for (i in 0..<count) {
    print matcher[i] + " "
}

Conclusion: She wants Shells not ashes Matches = 1 She

REGEX does not work like Windows CMD, for example, dir W * to specify a folder or files starts with W. What did I do wrong?

Thank you very much if you answer this question.

+3
source share
1 answer

In regular expressions *does not match wildcard (matches any characters).

, , , " ". Sh, e. , :

Sh
She
Shee
Sheee
etc...

, , , , \w* .

/\bShe\w*\b/

, " " , . , , "" . , , , , / .

+4

All Articles