• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Regular Expression

 
Vinod Awar
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 129
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried by removing the DOTALL option but iam getting the constructors first parameter from the last line only.
 
Henry Wong
author
Marshal
Pie
Posts: 20882
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Henry
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic