Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regex match any character 5 or more times

Tags:

regex

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.

like image 707
YsoL8 Avatar asked Jun 27 '11 10:06

YsoL8


People also ask

What does '$' mean in regex?

$ 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.

How do you find multiple occurrences of a string in regex?

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.

What regex matches any character?

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.


2 Answers

You want

^.{5,}$

But really - just use the built-in string length function of the language of your choice

like image 130
mhyfritz Avatar answered Sep 18 '22 15:09

mhyfritz


Try this regex:

 .{5,}

more chars to make up the minimum post...

like image 20
Bohemian Avatar answered Sep 17 '22 15:09

Bohemian