简体   繁体   English

以 # @ 开头的字符串模式,可以包含下划线和减号

[英]String pattern which starts with # @ and can contain underscore and minus

I try to make a string pattern that can contain UTF-8 characters (öäå, etc) and match the following criteria in Java (1.7);我尝试制作一个可以包含 UTF-8 字符(öäå 等)的字符串模式,并在 Java (1.7) 中符合以下条件;

  • Must start with # or @必须以 # 或 @ 开头
  • Must be lower-case必须小写
  • Can contain - or _ (minus and underscore), no other special char可以包含 - 或 _(减号和下划线),没有其他特殊字符
  • Can contain digits (0-9)可以包含数字 (0-9)
  • Min 3 and maximum 15 characters long最少 3 个和最多 15 个字符长

What I have at the moment that works but are missing many of the criteria.我目前所拥有的有效但缺少许多标准。

"#\\p{javaLowerCase}+" "#\\p{javaLowerCase}+"

I don't know how to complete and add the rest of the criteria.我不知道如何完成和添加其余的标准。 How would a regex expression look like that can accommodate the criteria I have?一个正则表达式看起来如何才能满足我的标准?

This translates into a regex in a relatively simple way:这以一种相对简单的方式转化为正则表达式:

"[#@][\\p{javaLowerCase}\\d_-]{2,14}"

This translates the "Min 3 and maximum 15 characters" inclusive of the # or @ at the beginning.这将翻译“最少 3 个和最多 15 个字符”,包括开头的#@ If these should not be counted, change the suffix to {3,15} .如果这些不应计算在内,请将后缀更改为{3,15}

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

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