I'm writing a simple debugging program that takes as input simple strings that can contain stars to indicate a wildcard match-any
*.wav // matches <anything>.wav
(*, a) // matches (<anything>, a)
I thought I would simply take that pattern, escape any regular expression special characters in it, then replace any \*
back to .*
. And then use a regular expression matcher.
But I can't find any Java function to escape a regular expression. The best match I could find is Pattern.quote
, which however just puts Q
and E
at the begin and end of the string.
Is there anything in Java that allows you to simply do that wildcard matching without you having to implement the algorithm from scratch?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…