Verify if String matches a format String

前端 未结 7 1768
旧巷少年郎
旧巷少年郎 2021-02-13 09:15

In Java, how can you determine if a String matches a format string (ie: song%03d.mp3)?

In other words, how would you implement the following function?

7条回答
  •  北海茫月
    2021-02-13 09:39

    There is not a simple way to do this. A straight-forward way would be to write some code that converts format strings (or a simpler subset of them) to regular expressions and then match those using the standard regular expression classes.

    A better way is probably to rethink/refactor your code. Why do you want this?

提交回复
热议问题