仅保留字符串数据中的字母数字字符

问题描述 投票:0回答:1

我正在流中获取字符串数据,我只想保留字母数字字符。我注意到Siddhi提供了正则表达式功能,如here所述。但问题是它返回一个布尔值而不是修改后的字符串。反正有直接获取修改后的字符串吗?这是我的代码。

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

是否有一个函数返回修改后的正则表达式字符串?

siddhi stream-processing wso2sp event-stream-processing
1个回答
0
投票

您不能使用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;
© www.soinside.com 2019 - 2024. All rights reserved.