Having regex patter like this: ab*d
why does it return match true for input abbbde
? How to change it to check also last character ?
Lets analyse your regex:
a - match an "a"
b* - match any number of b's
d - match a "d"
Because * matches any number of b's.
$ matches end of line, so
ab*d$
should match end of line (to make sure nothing follows)
Then again \s will match any whitespace so another option is
ab*d\s
You need to add a $
at the end of the pattern to ensure it is the last character ab*d$
.
A $
is called a End of String Anchor
in Regular Expressions. You can read more on Anchors here http://www.regular-expressions.info/anchors.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With