开发者

Regular expression with no maximum limit

开发者 https://www.devze.com 2023-01-02 22:24 出处:网络
I Need a regular expression which accepts all types of characters (alphabets, numbers and all special characters), and miniumum number of characters should be 15 and no l开发者_运维问答imit for maximu

I Need a regular expression which accepts all types of characters (alphabets, numbers and all special characters), and miniumum number of characters should be 15 and no l开发者_运维问答imit for maximum characters.


.{15,}

Assuming that you use settings where the dot matches all characters. It's really hard to be any more specific unless you mention which platform you're using.


The basic repetition options for regex are as follows:

  • x? matches zero or one x
  • x* matches zero or more x
  • x+ matches one or more x
  • x{3} matches exactly 3 x
  • x{3,} matches at least 3 x
  • x{3,5} matches at least 3 and at most 5 x

To match absolutely any character, you use . in single-line mode. To enable single-line mode, consult documentation for your specific language. In Java, this is (?s)/Pattern.DOTALL.

If by "all types of characters" you really mean everything but whitespace, then there's a special character class for that: \S (with a capital S). The pattern you're looking for is therefore:

  • \S{15,}

References

  • regular-expressions.info
    • Repetition
    • The Dot Matches (Almost) Any Character
    • Character Classes


Ehm.. Using a regular expression when you just want to check the length of a string? Try something like

inputString.Length >= 15

0

精彩评论

暂无评论...
验证码 换一张
取 消