简体   繁体   中英

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);

  • Must start with # or @
  • Must be lower-case
  • Can contain - or _ (minus and underscore), no other special char
  • Can contain digits (0-9)
  • Min 3 and maximum 15 characters long

What I have at the moment that works but are missing many of the criteria.

"#\\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. If these should not be counted, change the suffix to {3,15} .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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