Regular expression for at least 10 characters
I need a regular expression w开发者_如何学Gohich checks that a string is at least 10 characters long. It does not matter what those character are.
Thanks
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 .
This will match a string of any 10 characters, including newlines:
[\s\S]{10,}
(In general, .
does not match newlines.)
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 trim
ing functions to strip whitespace, example: if (length(trim(str)) > 10) lenGeq10=true...
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;
\S{10,}
disregard below:
extra characters in order to post.
精彩评论