File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes Regular Expression Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Regular Expression" Watch "Regular Expression" New topic

Regular Expression

Vinod Awar
Ranch Hand

Joined: Nov 06, 2006
Posts: 129
Hello java guru's,

iam using regular expressions. I have a html file from which i want to grab some text. The file contents are something like this

now from this code i want to take out the first parameter of the SL constructor and store in a ArrayList. i used a pattern like

but with this i get all four lines(i.e new SL() lines). is there a method in regex which returns all matches separately.

Vinod Awar
Ranch Hand

Joined: Nov 06, 2006
Posts: 129
I tried by removing the DOTALL option but iam getting the constructors first parameter from the last line only.
Henry Wong

Joined: Sep 28, 2004
Posts: 20538

By default a qualifier is greedy, so it will match the first "new SL('" all the way to the last "','". For what you will need, you will have to make the group 1 qualifier reluctant -- use (.*?) instead.


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
I agree. Here's the link:
subject: Regular Expression
It's not a secret anymore!