I want to split width and height from this String
String imgStyle = "width: 300px; height: 295px;";
int width = 300; // i want to get this value
int height = 295; // i want to get this value
I tried a lot of regular expressions but i can't get them.
String imgStyle = "width: 300px; height: 295px;";
int imgHeight = 0;
int imgWidth = 0;
Pattern h = Pattern.compile("height:([0-9]*);");
Pattern w = Pattern.compile("width:([0-9]*);");
Matcher m1 = h.matcher(imgStyle);
Matcher m2 = w.matcher(imgStyle);
if (m1.find()) {
imgHeight = Integer.parseInt(m1.group(2));
}
if (m2.find()) {
imgWidth = Integer.parseInt(m2.group(2));
}
java.lang.IllegalStateException: No successful match so far
I tried a lot of regular expressions but i can't get themPlease, post your attempts, so that we can see them and tell you what's wrong