Serial Binding + String Parsing +Regexpr

Thank you John and Rich.

Looks like it works.

Your suggestions were correct.

Double backslash does the trick.

But what I do first is - I installed OpenHAB designer (aka Eclipse mod)
Of course, what I noticed first is totally broken syntax highliting near the place where I defined regex string.

I added double backslaches, but result was still failed.

And here is the reason:

I tried to match WHOLE string using my regex, of course this was wrong.

Instead I need to use find facility.

And now rule looks like:

	var String data = GPRS_Shield.state.toString
	logInfo("[SERIAL GPRS]", data)
	
	var String regex = "CMGR.*\\s*(.*)\\s*OK"
	var Pattern pattern = Pattern::compile(regex, Pattern::MULTILINE)
	var Matcher m = pattern.matcher(data)
	if(m.find()) {
		logInfo("[GPRS5]", m.groupCount() + " " + m.group(1))
	}
1 Like