Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Pattern Matching

 
Santana Iyer
Ranch Hand
Posts: 335
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am doing small project like window search facility in java,
so I wanted to know when I give input in box (*.ext) or (filename*.ext)
is there any API available to do matching with existing file.
 
Garrett Rowe
Ranch Hand
Posts: 1296
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can check out java.util.regex.Pattern & java.util.regex.Matcher classes to get this functionality. Here is a link to the Sun tutorial on regular expressions.
 
Santana Iyer
Ranch Hand
Posts: 335
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, actually I was reading about it
but still I am not able to find right solution
if someone enters abc*.txt now what kind of regex to create
abc[*]* does not work nor abc[.]* works....
 
Garrett Rowe
Ranch Hand
Posts: 1296
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try this
 
Henry Wong
author
Marshal
Pie
Posts: 20889
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Santana Iyer:
Thanks, actually I was reading about it
but still I am not able to find right solution
if someone enters abc*.txt now what kind of regex to create
abc
  • * does not work nor abc[.]* works....


  • I agree that you should take the time to learn regex, it will come in really handy during your career. It is not simple to learn, but is a fantatic tool to use once you get comfortable with it....


    Anyway...

    To match "abc*.txt", use "abc.*\\.txt"

    Henry
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic