Я хочу разделить ширину и высоту от этой строкиJava регулярные выражения Захват группы
String imgStyle = "width: 300px; height: 295px;";
int width = 300; // i want to get this value
int height = 295; // i want to get this value
Я попытался много регулярных выражений, но я не могу получить их.
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: Нет успешный матч до сих пор
'Я пробовал много регулярных выражений, но я не могу получить them' Пожалуйста, оставьте свои попытки, так что мы можем их увидеть и сказать вам, что не так – BackSlash