How to do dynamic RegEx?

I want to create a regular expression based on a user input from a search field. Using this regex, I want to filter a list of objects.
This one works:

However, I want to have a user defined search term, so I was trying this:

where the variable regex is set to:

This leads to the following error:

bundle.js:23 Uncaught (in promise) TypeError: regex.test is not a function
    at callback (bundle.js:23)
    at bundle.js:28
    at (<anonymous>)
    at bundle.js:26
    at Object.onClick (bundle.js:34)
    at runHandler (sdk.js:14)
    at i.available.n.<computed> (sdk.js:14)
    at (sdk.js:14)
    at ja (sdk.js:14)
    at ka (sdk.js:14)

I also noted that I can only connect raw text to “pattern/regexp” plug. That’s why I used raw text when defining regex variable.

So, how to build a dynamic regex?


Hello @Klaas_Klever

Seems like there is no way to specify a dynamic RegExp, thank you for pointing us about that!
I just created an internal ticket BKNDLSS-25836 to add that block.

However, for implementing a simple search you do not need the RegExp block, it can be done with a simple string contains block:

Take a look at this demo:

Regards, Vlad

Yes. I can use String contains to start with, but Regex will be much more powerful.

could you please provide cases where you need RegExp for this kind of search?

For instance, regex offers an OR operator, and wildcards.

ok, it makes sense

Hello @Klaas_Klever

We have added a new Codeless block to specify a dynamic RegExp. The old block will be deprecated


Great! I will try …