I have this regex pattern:
^[.]{5,}$
Which I want to return true if the tested string has 5 or more characters.
I.E it'll only return false if the string contains 4 or less characters.
At the moment it seems to return true regardless of the number of characters and I can't see why.
$ means "Match the end of the string" (the position after the last character in the string). Both are called anchors and ensure that the entire string is matched instead of just a substring.
Method 1: Regex re. To get all occurrences of a pattern in a given string, you can use the regular expression method re. finditer(pattern, string) . The result is an iterable of match objects—you can retrieve the indices of the match using the match.
By default, the '. ' dot character in a regular expression matches a single character without regard to what character it is. The matched character can be an alphabet, a number or, any special character.
You want
^.{5,}$
But really - just use the built-in string length
function of the language of your choice
Try this regex:
.{5,}
more chars to make up the minimum post...
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