Skip to content

Get values from json using multiregex #13

Description

@theunreal

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions