I want to route messages based on content, however my regex for doing so doesn't match what I throw at it. Why is that so?
I've tried some online regex test websites and on these websites, I get a full match. I've also adapted my regex to ".*\{value=1\}.*"
, which works as expected, but I think my original solution might be more robust.
This is my route:
<from uri="milo-client:opc.tcp://localhost:12685?allowedSecurityPolicies=None&node=RAW(ns=2;s=items-machine_lfm_reset)&overrideHost=true"/>
<choice>
<when>
<simple>${bodyAs(String)} regex "/\bvalue=1\b/"</simple>
<log message="Value was 1."/>
</when>
<choice>
This is the message that comes in:
DataValue{value=Variant{value=1}, status=StatusCode{name=Good, value=0x00000000, quality=good}, sourceTime=DateTime{utcTime=132061080449440000, javaDate=Thu Jun 27 11:20:44 GMT 2019}, serverTime=DateTime{utcTime=132061080459370000, javaDate=Thu Jun 27 11:20:45 GMT 2019}}
I expected this regex to match, because if I enter my message and regex on any regex testing website, I get a match, but actually I don't get a match and my when statement isn't fulfilled.
Your input actually does not match this regex. Simple function regex
uses Matcher#matches()
method, which returns true only for full match.
If you have seen this regex to match in some tester website, then it is probably using Matcher#find()
, which returns true even for partial match.
https://www.regexplanet.com/share/index.html?share=yyyydc68p6r
Returns: true if, and only if, the entire region sequence matches this matcher's pattern
User contributions licensed under CC BY-SA 3.0