0

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?

4

1 回答 1

5

您不能使用str:regexp()函数来修改字符串,它只能用于检查字符串是否与给定字符串匹配,而是可以使用该str:replaceAll()函数删除不需要的字符,如下所示

@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;

您可以从这里找到有关字符串函数的更多信息

于 2019-11-14T05:10:43.180 回答