本文介绍了普通的前pression匹配的五个字maximium的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个正规的前pression

I have a regular expression

^[a-zA-Z+#-.0-9]{1,5}$

这将验证字包含字母数字字符和一些特殊字符,长度

不应该超过 5 字符。

which validates that the word contains alpha-numeric characters and few special characters and length should not be more than 5 characters.

我如何让这个普通的前pression接受匹配上述正前pression最多五个字。

How do I make this regular expression to accept a maximum of five words matching the above regular expression.

推荐答案

^ [A-ZA-Z +#\\ - 0-9] {1,5}(\\ S [A-ZA -Z +#\\ - 0-9] {1,5}){0,4} $

此外,您还可以使用例如 [] 而不是 \\ S 如果你只是想接受的空间,没有标签和换行符。你可以写 [] + (或 \\ S + )的任何数量的空格(或空格),而不仅仅是之一。

Also, you could use for example [ ] instead of \s if you just want to accept space, not tab and newline. And you could write [ ]+ (or \s+) for any number of spaces (or whitespaces), not just one.

编辑:删除无效的解决方案,并通过固定提到unicornaddict的bug

Removed the invalid solution and fixed the bug mentioned by unicornaddict.

这篇关于普通的前pression匹配的五个字maximium的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 13:32