简体   繁体   中英

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?

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(...))
  • Check if the string after '-' equals '000'

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