Reputation: 196
I'm having a little trouble figuring out what to do.
Basically using java I'm trying to:
I want to find the content after a certain string in this case being
title="
The first and last steps are simple for me but I'm having no luck (and never had with regex).
I believe this is the beginning of what I need:
String regex = "(?<=title=\")\\S+";
Pattern name = Pattern.compile(regex);
After that I have no clue. Any help?
Upvotes: 0
Views: 114
Reputation: 43663
import java.util.regex.Matcher;
import java.util.regex.Pattern;
String EXAMPLE_TEST = "......";
Pattern pattern = Pattern.compile("(?<=title=\")(\\S+)")
Matcher matcher = pattern.matcher(EXAMPLE_TEST);
while (matcher.find()) {
System.out.println(matcher.group());
}
Note: You might consider to use regex pattern (?<=title=\")([^\"]*)
Upvotes: 1
Reputation: 38173
List<String> result_list = new ArrayList<String>();
Pattern p = Pattern.compile("title=\"(.*)\"");
Matcher m = p.matcher("title=\"test\"");
boolean result = m.find();
while(result)
{
result_list.add(m.group(0));
result = m.find();
}
Upvotes: 0