Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get values from json using multiregex #13

Open
theunreal opened this issue Apr 1, 2020 · 0 comments
Open

Get values from json using multiregex #13

theunreal opened this issue Apr 1, 2020 · 0 comments

Comments

@theunreal
Copy link

theunreal commented Apr 1, 2020

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant