Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

can i use wild card query in endswith method in java

Tags:

java

i need to get all the files ends with .doc and i have some custom extensions like .doc.25-40, .doc2 etc..i need to get all the extensions with .doc.*

filename.endsWith(".doc.*"); 

fails why?

like image 497
ramya Avatar asked Mar 06 '26 17:03

ramya


1 Answers

No, that doesn't work. Java doesn't support simple wildcards. You would have to use a Regex method, e.g.:

filename.matches(".*\\.doc.*")

Explanation:

.*   // any text
\\.  // a period
doc  // "doc"
.*   // any text
like image 167
Sean Patrick Floyd Avatar answered Mar 08 '26 07:03

Sean Patrick Floyd



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!