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

regular expression problem

 
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 aefbc d cf
ad c bc ae
ef ab df c b
e g af c b c
abcdef
fdaebc

i have via string tokenizer got the individual strings,
now i need to get how many lines match string "abc",for example first line
has two strings which contains "abc",i.e it is not essential that we may need to get a than b than c,they maynot occur continuosly,like fifth and sixth line contains string abc.

can any one suggest logic of doing this in java
 
Muhammad Saifuddin
Ranch Hand
Posts: 1324
Android Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you should read ShowSomeEffort first.
 
Piet Verdriet
Ranch Hand
Posts: 266
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
puneet, you've recieved some helpful replies here:
http://forum.java.sun.com/thread.jspa?threadID=5282355
yet you choose to abandon that thread without saying anything? Rather rude, if you ask me.
 
Puneet N Vyas
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i tried writing it ,i wrote ".*a.*b.*c"
but it matches those abc which are separated in more than one line,
for example
it matches:
a bc deab c
what i need is that,it should match
defabc f
cdea f

and so on..
 
Henry Wong
author
Marshal
Pie
Posts: 20902
76
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
but it matches those abc which are separated in more than one line,
for example
it matches:
a bc deab c


I think you have a different definition what what is a "line". With text files a "line", ends with a carriage return / line feed. So, in your example, there is only one line. Please explain to us what you mean by a "line".

what i need is that,it should match
defabc f
cdea f


Please explain to us what you mean by a "line" with this too -- as there isn't even a "b" in the second line. With text files, there are two lines here.

How many are there under your definition? What are they? And what do you expect to match?

Henry
 
Puneet N Vyas
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry for misleading,ya that is the meaning of line,also i wrote incorrectly my problem,consider the following lines
f fabcde
fdaebc af f f
i need to write regular expression for matching "abc",the above line matches abc,where as below lines doesnot,
de a a
a bc def a de


thanks for support
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic