• Post Reply Bookmark Topic Watch Topic
  • New Topic

how to match  RSS feed

 
Puneet N Vyas
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
consider the following lines of a text file:
a abc ac d cf
ad c bc ae
ef ab df c b
e g af c b c

now i need to get how many lines match string "a a",for example first and second lines matches the string,i.e it is not neccessary that string a a occurs continuosly,like in second line first a comes then space then last string contains a..

can any one suggest logic of doing this in java
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That sounds like a job for regular expressions. The expression to look for would be "a.* .*a" (in other words, first an "a", then optionally various other characters, a space, more optional other characters, and another "a"). Here's an example of how to use regexps in Java.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!