Reputation: 15492
given this text:
RULE deviceType=IPHONE_DEVICE&ClientVersion>=4.10 { bla1 \ }
RULE deviceType=ANDROID_DEVICE&ClientVersion>=4.5 { bla2 \ }
I want to use java regex to fetch this text:
bla1
bla2
I have tried:
Pattern pattern = Pattern.compile("(.*?)RULE deviceType=ANDROID_DEVICE&ClientVersion>=4.5 \\{(\\w+)\\ \\}(.*)");
Matcher matcher = pattern.matcher(stringMap);
if (matcher.find()) {
androidSection = matcher.group(1);
}
but the code returned zero matches.
What am i missing?
Upvotes: 1
Views: 48
Reputation: 785531
You can change your regex to this:
RULE deviceType=\w+&ClientVersion>=[\d.]+\h*\{\h*(\w+)\h*\\\h*}
Using Java use this regex:
final String regex =
"RULE deviceType=\\w+&ClientVersion>=[\\d.]+\\h*\\{\\h*(\\w+)\\h*\\\\\\h*\\}";
Upvotes: 1