Regex Matching

This demonstrates event cleansing using regex expressions.

Regex operations can be performed using Siddhi Execution Regex extension.

define stream SweetProductionStream (name string, amount int);

@info(name='ProcessSweetProductionStream')
from SweetProductionStream
select name, 
   regex:matches('chocolate(.*)', name) as isAChocolateProduct, 
   regex:group('.*\s(.*)', name, 1) as sweetType
insert into ChocolateProductStream;
define stream SweetProductionStream (name string, amount int);

Defines SweetProductionStream having information of name and amount

@info(name='ProcessSweetProductionStream')
from SweetProductionStream
select name, 
   regex:matches('chocolate(.*)', name) as isAChocolateProduct, 

Matches if name begins with the word ‘chocolate’

   regex:group('.*\s(.*)', name, 1) as sweetType

Captures the sweetType of the sweet following the flavour in name

insert into ChocolateProductStream;

Input

Below event is sent to SweetProductionStream,

['chocolate cake', 34]

Output

After processing, the event arriving at ChocolateProductStream will be as follows:

['chocolate cake', true, 'cake']

Top