GeeCON Prague 2014*
The moose likes Beginning Java and the fly likes regular expression problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "regular expression problem" Watch "regular expression problem" New topic
Author

regular expression problem

Puneet N Vyas
Ranch Hand

Joined: Sep 20, 2007
Posts: 61
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

Joined: Dec 06, 2005
Posts: 1321

I think you should read ShowSomeEffort first.


Saifuddin..
[Blog][Linkedin] How To Ask Questions On JavaRanch My OpenSource
Piet Verdriet
Ranch Hand

Joined: Feb 25, 2006
Posts: 266
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

Joined: Sep 20, 2007
Posts: 61
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
Sheriff

Joined: Sep 28, 2004
Posts: 18874
    
  40

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


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Puneet N Vyas
Ranch Hand

Joined: Sep 20, 2007
Posts: 61
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
 
GeeCON Prague 2014
 
subject: regular expression problem