Topic: Possibly useful regex to parse Ruby Hash.inspect into other languages

This is a Java snippet I'm using to parse the output of Ruby's Hash.inspect into a Java HashMap. Seems like it might be useful if/when we have to bridge the gap from Ruby to something else.

Its for a quick HTTP interface. I have a Java daemon that needs some info from a ruby app. The ruby app just calls

render :status => 200, :text => myrubyhash.inspect

The following java snippet turns the output of Ruby's Hash.inspect into key value pairs.

// build the regex ":(.*?)=>\"(.*?)\"" so that its case insensitive, multiline, and DOT matches all characters
Pattern pattern = Pattern.compile(
                    ":(.*?)=>\"(.*?)\"",
                    (Pattern.MULTILINE | Pattern.CASE_INSENSITIVE | Pattern.DOTALL));

//apply the pattern to our string content
            Matcher matcher = pattern.matcher(content);

//while there are matches found
            while (matcher.find()) {
                logger.debug("Regex hit: " + matcher.group());

//get the first group which is the hashes key
                logger.debug("Group 1: " + matcher.group(1));
//the second is the value for that key
                logger.debug("Group 2: " + matcher.group(2));

                retval.put(matcher.group(1), matcher.group(2));
            }


So putting it out there. I hope it helps someone, and if anyone sees any kinks in it please let me know!