Question: Is there a simpler way, other than String matching, to parse the below string? :

```
com.atlassian.greenhopper.service.sprint.Sprint@719c9e23
    [name=Sprint 1,
     closed=true,
     startDate=2013-04-10T17:58:49.228-07:00,
     endDate=2013-04-24T17:58:49.228-07:00,
     completeDate=2013-04-16T14:42:09.504-07:00,id=10]

```

I am interested in getting the `name`,`closed` and other such values.

(This string is an element of a JSONArray, type `org.codehaus.jettison.json.JSONArray`, that I'm getting from JIRA.)

Answer: 
This is the way I did it, that is readable and does not involve regex.

```
String keyValue = str.substring(str.indexOf("[") + 1, str.lastIndexOf("]"));
StringTokenizer tok = new StringTokenizer(keyValue, ",");
Map<String, String> map = new LinkedHashMap<String, String>();
while (tok.hasMoreTokens()) {
    String entString = tok.nextToken();
    map.put(entString.split("=")[0], entString.split("=")[1]);
}

```

From this point, I get values I need by doing

```
map.get("name")

```
So this may not be valid JSON but if the form will be the same every time (in terms of no extra levels of nesting) it should be parsable by a regex. 

First capture the array using this regex `\[(.*)\]`, the group in the middle will be the data. Then split that data on `,`. Now you have an array where each entry can easily be parsed by a regex of your choosing, unless the entries follow some sort of form that you haven't told us, or I'm not catching, each entry will need it's own specific regex which should be relatively easy to write. 

In addition I wasn't sure if the part at the begining 

> 
> com.atlassian.greenhopper.service.sprint.Sprint@719c9e23 
> 
> 
> 

was important data but that can also be parsed by another regex 

> 
> **Solution 2**
> 
> 
> 

So another solution converts the string to valid JSON using 2 regex operations. 

First `String result = searchText.replaceAll("(.|\\n)*(\\[(.|\\n)*\\])", "$1");'\` 

This basically just removes that big string from the front. 

Next 

`result = searchText.replaceAll("(\\w*)=([^,\\]]*)", "\"$1\" : \"$2\"");` 

This regex just fixes up the array to make it a valid JSON array, you can now use your JSON parser on the string. As for not using regexes in your solution I say **why not**, a regex is one of the most expressive tools in programming some people over use them but this is a perfect case to use one