简体   繁体   English

Java 匹配字符串格式

[英]Java Match string format

So I want to match a string to a simple mask but I would like to avoid using regex because my client have access to this mask and can change it.所以我想将一个字符串与一个简单的掩码匹配,但我想避免使用正则表达式,因为我的客户可以访问这个掩码并且可以更改它。

Is it possible to have a string matches something like #####-000?是否可以让字符串匹配 #####-000 之类的内容?

Or I have no choice but to convert my simple mask to regex ?或者我别无选择,只能将我的简单掩码转换为正则表达式?

Thank you.谢谢你。

If I get your question (and the comments) the right way, you could do the following:如果我以正确的方式收到您的问题(和评论),您可以执行以下操作:

  • Split your string at '-'在“-”分割你的字符串
  • Check if string before '-' has length 5 and is numeric (StringUtils.isNumeric(...))检查 '-' 之前的字符串是否长度为 5 并且是数字 (StringUtils.isNumeric(...))
  • Check if the string after '-' equals '000'检查'-'后面的字符串是否等于'000'

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

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