I'm getting string data in a stream and I would like to keep only the alphanumeric characters. I noticed that Siddhi offers a regexp function, as mentioned here. But the thing is it returns a Boolean instead of the modified string. Is there anyway to get the modified string directly? This is my code.
@App:name("strtest")
@App:description("Description of the plan")
-- Please refer to https://docs.wso2.com/display/SP400/Quick+Start+Guide on getting started with SP editor.
define stream InboundStream(ipstring string);
@sink(type='log', prefix='Modified string')
define stream Opstream(ropstring bool);
from InboundStream
select str:regexp(ipstring, "^A-Za-z0-9") as ropstring insert into Opstream;
Is there a function that returns the modified regex string?
You can't use str:regexp()
function to modify the string it can be only used to check whether a string matches a given string, instead you can use the str:replaceAll()
function to remove the unwanted characters as shown below
@App:name("strtest")
@App:description("Description of the plan")
define stream InboundStream(ipstring string);
@sink(type='log', prefix='Modified string')
define stream Opstream(ropstring string);
from InboundStream
select str:replaceAll(ipstring, '[^a-zA-Z0-9]', '') as ropstring
insert into Opstream;
You can find more about functions on string from here