正则表达式至少10个字符

时间:2022-09-28 23:23:41

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

我需要一个正则表达式来检查一个字符串是否至少10个字符长。这些角色是什么并不重要。

Thanks

谢谢

5 个解决方案

#1


24  

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.

自从。默认情况下,与换行符不匹配,您必须使用合适的修饰符(如果您的正则表达式引擎支持)。甚至匹配换行符。在Perl中的示例,您可以使用s修饰符。

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

或者,您可以使用[\ s \ S]或[\ d \ D]或[\ w \ W]代替。

#2


7  

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

这将匹配任意10个字符的字符串,包括换行符:

[\s\S]{10,}

(In general, . does not match newlines.)

(通常,。与新行不匹配。)

#3


4  

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

您使用的语言是否没有字符串长度函数(或具有此类函数的库)?实施自己的很难吗?对于正则表达式来说这似乎有些过分,但如果你真的想要,你可以使用类似。{10,}的东西。在具有长度函数的语言中,它可能看起来像if(str.length()> 10)lenGeq10 = true或if(length(str)> 10)lenGeq10 = true等等......如果空白是一个有意义的话,许多库也有剥离空格的转移函数,例如:if(length(trim(str))> 10)lenGeq10 = true ...

#4


1  

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

一个C#解决方案,用于查看字符串是否与您的参数所定义的一样重要。

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

ItMatters = myString.Length >= 10;

#5


-1  

\S{10,}

\ S {10,}


disregard below:

无视以下内容:

extra characters in order to post.

额外的字符,以便发布。

#1


24  

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.

自从。默认情况下,与换行符不匹配,您必须使用合适的修饰符(如果您的正则表达式引擎支持)。甚至匹配换行符。在Perl中的示例,您可以使用s修饰符。

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

或者,您可以使用[\ s \ S]或[\ d \ D]或[\ w \ W]代替。

#2


7  

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

这将匹配任意10个字符的字符串,包括换行符:

[\s\S]{10,}

(In general, . does not match newlines.)

(通常,。与新行不匹配。)

#3


4  

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

您使用的语言是否没有字符串长度函数(或具有此类函数的库)?实施自己的很难吗?对于正则表达式来说这似乎有些过分,但如果你真的想要,你可以使用类似。{10,}的东西。在具有长度函数的语言中,它可能看起来像if(str.length()> 10)lenGeq10 = true或if(length(str)> 10)lenGeq10 = true等等......如果空白是一个有意义的话,许多库也有剥离空格的转移函数,例如:if(length(trim(str))> 10)lenGeq10 = true ...

#4


1  

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

一个C#解决方案,用于查看字符串是否与您的参数所定义的一样重要。

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

ItMatters = myString.Length >= 10;

#5


-1  

\S{10,}

\ S {10,}


disregard below:

无视以下内容:

extra characters in order to post.

额外的字符,以便发布。