Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regular expression for at least 10 characters

Tags:

regex

I need a regular expression which checks that a string is at least 10 characters long. It does not matter what those character are.

Thanks

like image 687
zee Avatar asked Dec 01 '10 15:12

zee


People also ask

What is the regular expression for characters?

A regular expression (shortened as regex or regexp; sometimes referred to as rational expression) is a sequence of characters that specifies a search pattern in text. Usually such patterns are used by string-searching algorithms for "find" or "find and replace" operations on strings, or for input validation.

How do I limit the length of a character in regex?

The ‹ ^ › and ‹ $ › anchors ensure that the regex matches the entire subject string; otherwise, it could match 10 characters within longer text. The ‹ [A-Z] › character class matches any single uppercase character from A to Z, and the interval quantifier ‹ {1,10} › repeats the character class from 1 to 10 times.

What is ?= * In regular expression?

?= is a positive lookahead, a type of zero-width assertion. What it's saying is that the captured match must be followed by whatever is within the parentheses but that part isn't captured.

What is difference [] and () in regex?

In other words, square brackets match exactly one character. (a-z0-9) will match two characters, the first is one of abcdefghijklmnopqrstuvwxyz , the second is one of 0123456789 , just as if the parenthesis weren't there. The () will allow you to read exactly which characters were matched.


1 Answers

You can use:

.{10,}

Since . does not match a newline by default you'll have to use a suitable modifier( if supported by your regex engine) to make . match even the newline. Example in Perl you can use the s modifier.

Alternatively you can use [\s\S] or [\d\D] or [\w\W] in place of .

like image 95
codaddict Avatar answered Sep 28 '22 07:09

codaddict