multiregexp
multiregexp copied to clipboard
Get values from json using multiregex
Using Java Pattern, I used to have something like this:
public String getAttributeFromMessage(String receiveData, Pattern patternToSearch) {
Matcher matcher = patternToSearch.matcher(receiveData);
if (matcher.find()) {
return matcher.group(1);
}
return "";
}
Using this library I did something like this:
String[] patterns = new String[]{
"\"field1\":\\s*\"(.*?)\"",
"\"field2\":\\s*(\\d+)(\\.\\d)?",
"\"field3\":\\s*\"(.*?)\""
};
this.matcher = MultiPattern.of(patterns).matcher();
...
public String getAttributeFromMessage(String receiveData) {
int[] match = this.matcher.match(receiveData);
??
}
I'm not sure how I can extract the values that the matcher has found, using Java.pattern I could do matcher.group(1) to get the string.
Any idea?