• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

java.util.regex for searching

 
Jeffry Kristianto Yanuar
Ranch Hand
Posts: 759
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys, my name is Jeffry. Can you help me to pattern used by the regex to do simple searching?

Assuming I have an ArrayList that contains movies title like this:
Batman
Batman Forever
Batman Returns
Batman Begins
Batman, the Dark Knight //coming soon in July 2008

when I search with the word "bat", I want the movies title above are print in the screen to prove that the pattern is right as well as I search using the word "man" (if there is a title named "Superman", it will print too).

Thanks for your help. Currently I'm developing DVD Rental application in my thesis project.


Thanks


Jeffry Kristianto Yanuar
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there a particular reason you want to use regexps? It seems that this could be easily done using a couple of String.indexOf calls.
 
Jeffry Kristianto Yanuar
Ranch Hand
Posts: 759
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there a particular reason you want to use regexps? It seems that this could be easily done using a couple of String.indexOf calls.


Nope, but if you have the solution with "a couple of String.indexOf calls" as you said, I'll take your solution. This is my own project, developed only by me and I only need simple searching like I posted before.


Thanks

Jeffry Kristianto Yanuar.
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Instead of just giving out solutions, we prefer to lead people to them. You could iterate through the List, and check indexOf("bat") and indexOf("man") to each element of it. You probably want to lowercase the array elements before calling indexOf to make sure you find "Man" as well as "man".
 
Jeffry Kristianto Yanuar
Ranch Hand
Posts: 759
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok Ulf, I'll try.


Thanks


Jeffry Kristianto Yanuar.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic