regexwso2regex-groupsiddhiwso2-streaming-integrator

Regex is not working properly inside WSO2 but giving proper response on java regex tester


I have a json in text format on which i am using regex to extract part of it. My regex is working fine on online java regex tester but same regex is giving me null in wso2 stream processor.

Regex : "(after)":("(\\"|[^"])*"|\[("(\\"|[^"])*"(,"(\\"|[^"])*")*)?\])

Sample json:

{"type":"int64","optional":true,"field":"h"}],"optional":false,"name":"io.debezium.connector.mongo.Source","field":"source"},{"type":"string","optional":true,"field":"op"},{"type":"int64","optional":true}],"optional":false,"name":"topic1"},"payload":{"after":"{\"_id\": {\"$oid\": \"dsfsddsef\"},\"code\": \"42443242\",\"name\": \"NAME1\",\"desc\": \"DESCRIPTIONt\",\"transRefId\": \"43242FSFESFS\",\"origAmount\": 1000,\"amount\": 1000,\"currency\": \"USD\",\"updatedAt\": \"2019-12-07T18:27:10.764Z\",\"message\": \"\"}","patch":null,"source":{"version":"0.10.0.Final","connector":"mongodb","name":"ayapayuat","ts_ms":1575862490000,"snapshot":"true","db":"DB","collection":"COLL1","ord":1,"h":0},"op":"r","ts_ms":1575862492251}}

Source config:

@source(type='kafka',
        topic.list='demo',
        partition.no.list='0',
        threading.option='single.thread',
        group.id="group",
        bootstrap.servers='localhost:9092',
 @map(type='text',fail.on.missing.attribute='false',regex.A=""" "(after)":("(\\"|[^"])*"|\[("(\\"|[^"])*"(,"(\\"|[^"])*")*)?\]) """,
                @attributes(payload = 'A[2]')))
define stream transactionstream1(payload string);

I want to extract everything under "payload"


Solution

  • I see you have surrounded the regex with spaces, Try it by trimming those.