zee
zee

Reputation: 177

Regular expression for at least 10 characters

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

Upvotes: 15

Views: 30999

Answers (5)

Jeff LaFay
Jeff LaFay

Reputation: 13350

A C# solution to see if the string matters as defined by your parameters..

string myString = "Hey it's my string!";
bool ItMatters;

ItMatters = myString.Length >= 10;

Upvotes: 0

Does the language you're using not have a string length function (or a library with such a function)? Is it very difficult to implement your own? This seems overkill for regex, but you could just use something like .{10,} if you really wanted to. In langauges that have length functions, it might look something like if (str.length()>10) lenGeq10=true or if (length(str) > 10) lenGeq10=true, etc... and if whitespace is a concernt, many libraries also have triming functions to strip whitespace, example: if (length(trim(str)) > 10) lenGeq10=true...

Upvotes: 4

codaddict
codaddict

Reputation: 454960

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 .

Upvotes: 36

robert
robert

Reputation: 34398

This will match a string of any 10 characters, including newlines:

[\s\S]{10,}

(In general, . does not match newlines.)

Upvotes: 8

Keng
Keng

Reputation: 53101

\S{10,}


disregard below:

extra characters in order to post.

Upvotes: -1

Related Questions