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: `&lt; 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;
}

```
['https://Stackoverflow.com/questions/12207102', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1603861/']
There is nothing wrong with this, and you don't need to do anything about it.

In Python 2, a `str` is similar to a C string - it's just a sequence of bytes, sometimes incorrectly assumed to be ASCII text. It can contain *encoded* text, e.g. as UTF-8 or ASCII.

The `unicode` type represents an actual string of text, similar to a Java `String`. It is text in the abstract sense, not tied to a particular encoding. You can decode a `str` into `unicode`, or encode a `unicode` into a `str`.

JSON keys and values are strings - they are not byte arrays, but text - so they are represented by `unicode` objects in Python.

If you need JSON output for use in another language, use the `json` module to produce it from your dictionary:

```
>>> import json
>>> print json.dumps({u'words': [u'every', u'single', u'word']})
{"words": ["every", "single", "word"]}

```
It is preferable, yes, since JSON is defined to be unicode.

If you have more specific things that are causing you trouble you should share them, otherwise I'd recommend watching [Ned Batchelder's Intro](http://bit.ly/unipain) if you're just generally uncomfortable with Unicode (in Python in particular). I don't know what is causing this to be a nuisance to you, since I don't know what you're doing with this dict.