Question

Regex question for Tosca Module Attributes

  • 13 December 2023
  • 3 replies
  • 86 views

Badge

I have seen a few other questions similar to this, but not quite the same.

 

Say I have a Module and a Module Attribute that I want to work for 2 different objects on the page. One has a Title of “Product A” and the other is “Product B”.

If I set the Title value to this:

{REGEX["^(Product A|Product B)$"]}

it works fine. However if I try to extract the common text to put it before REGEX like this:

Product {REGEX["^(A|B)$"]}

then it fails stating “Invalid combination of values.”. Any suggestions on how to get the common text out of the REGEX? I tried with double quotes around “Product” as well but it gave the same error.


3 replies

Userlevel 2
Badge

I think if you use REGEX then the entire value has to be in the REGEX - you can’t combine it with other values.
So for your example, something like {REGEX[“^Product (A|B)$”]} should work fine.

That’s assuming you need the value to be that precise, rather than going for a simpler value withiout the REGEX, like Product *.

Userlevel 2
Badge

another way that should be fine too

{REGEX["^Product [AB]$"]}

 

Userlevel 2
Badge

and you can also quickly setup a small test to verify REGEX expressions
 

 

Reply