Verify if String matches a format String

前端 未结 7 2236
误落风尘
误落风尘 2021-02-13 08:55

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:49

    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?

提交回复
热议问题