【问题标题】:Keep only alphanumeric characters in string data在字符串数据中只保留字母数字字符
【发布时间】:2019-11-13 13:26:00
【问题描述】:

我在流中获取字符串数据,我想只保留字母数字字符。我注意到 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】:

    你不能使用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;
    

    你可以从here找到更多关于字符串的函数

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-04-09
      • 2016-03-16
      • 1970-01-01
      • 1970-01-01
      • 2019-05-26
      • 2017-09-03
      • 1970-01-01
      相关资源
      最近更新 更多