简体   繁体   English

如何在 Spring 应用程序中为名称模式创建包含和排除字符的正则表达式

[英]How to create regex for name pattern with include and exclude characters in Spring application

I want to create regex with following conditions我想创建具有以下条件的正则表达式

  1. Cannot include ` / * ?不能包含` / * ? " < > | " < > | (space character) , # (空格字符) , #
  2. Cannot start with - _ +不能以- _ +开头
  3. Cannot be.不可能是。 or .. or ..

Here is my regex:这是我的正则表达式:

[^A-Z+\/\\*?"<>|`` `,#.][a-z0-9_+-]+

Above regex satisfy above condition [1] and [3] but not [2].以上正则表达式满足上述条件 [1] 和 [3] 但不满足 [2]。 How should I satisfy above conditions using the regex?我应该如何使用正则表达式满足上述条件?

Something like:就像是:

^[a-zA-Z0-9][a-zA-Z0-9_-]*$

Should work, though no periods would be acceptable at all, not just the .应该可以工作,尽管根本不接受任何时期,而不仅仅是. and .. patterns...模式。

edit, maybe?编辑,也许?

^[a-zA-Z0-9][a-zA-Z0-9_-][^.][^..]*$

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM