This regular expression is not finding any matches. In other languages I run it in, it works great. In online regular expression testers like rubular.com it works great.
In java, it does not work.
What is different about java regular expressions that they break things like this?
Why doesn’t it work? Furthermore, how can I figure out in the future why they wont match?
sample data
<link>http://www.wunderground.com/US/MI/Milan.html</link>
<description><![CDATA[Temperature: 89.4°F | Humidity: 62% | Pressure: 29.65in (Steady) | Conditions: Clear | Wind Direction: NW | Wind Speed: 1.6mph<img src="http://server.as5000.com/AS5000/adserver/image?ID=WUND-00070&C=0" width="0" height="0" border="0"/>]]>
</description>
and the code
protected void parseTemperature()
{
Pattern p = Pattern.compile("/Temperature: ([0-9.]+)°/");
Matcher m = p.matcher(this.xml);
if (m.find())
{
this.temperature = Double.valueOf(m.group(1));
}
}
Remove the
/characters surrounding the regex.Pattern.compiletakes a raw expression, not wrapped in/s.