I am currently working on a University assignment, and have a (most likely simple) question regarding regex / regular expressions.
To summarize; this assignment is a simple RSS feed manager, which uses JSP and a RESTful web service.
I am currently working on a section of the assignment spec which requires me to be able to input XML feed data (e.g. <feeds><feed><name>FEED NAME</name><uri>http://FEEDuri/</uri></feed></feeds> etc..) and from this data, extract the FEED NAME & FEEDuri via regex.
My lecturer has provided a base method for us to work off, and I think I have implemented it correctly within my RESTful web service, and now I am implementing error handling.
I have successfully implemented error handling for the case where there is no data input by user. My question is this: Based on the example method (below), is it possible to implement error handling for the case where the feed format input is incorrect
eg: < fed> FEED NAME < /fiid> < uro>http://FEEDuri< /pro>The XML tags here are obviously incorrect.
Will regex ONLY pull the group from the String IF it lies between the defined values passed as the arguement to the compile method?
To supplement my question, here is the base method given to us to use (instead of an XML parser):
public static List<Feed> getFeedsFromXml(String xml) {
Pattern feedPattern = Pattern.compile("<feed>\\s*<name>\\s*([^<]*)</name>\\s*<uri>\\s*([^<]*)</uri>\\s*</feed>");
Matcher feedMatch = feedPattern.matcher(xml);
while (feedMatch.find()) {
String feedName = feedMatch.group(1);
String feedURI = feedMatch.group(2);
feeds.add(new Feed(feedName, feedURI));
}
return feeds;
}