Why is the Regex expression not matching accordingly?

Hi   I’ve created a custom regex at https://regex101.com/ which should match a special set of characters;  !"`'#%&,:;<>=@{}~$()*+?. This gives the Regex expression: [!"`'#%&,:;<>=@{}~$()*+?\[\]\^\|]+ An example string : “!code”  gets matched accordingly to the pattern (it contains “!”). When I use this pattern in Mendix with the “isMatch” function, to know whether a String has special characters,ike  isMatch($String,'[!"`''''#%&,:;<>=@{}~$()*+?\[\]\^\|]+') In Mendix the example string “!code” gets NOT MATCHED, while it should be (it contains “!”).   This brings me to the question, why is the regex pattern working on the regex site and not in Mendix? Is there something I missed? Thanks, EDIT1: Using same regex as Regex expression in a Entity validation rule DOES MATCH the example string, strange.
2 answers

Because isMatch implicitly appends ^ at the start and $ at the end. To get around that you will have to add * at the front and the endSee this doc for more information.

One more advise: do create unittests, and create enough of them to make sure you always get the result you expect.


I would be tempted to set up a constant that you can use, and then you don’t have to worry about escaping any characters:

The above is one we have used for validating the correct format of a UK NI number but the principle is the same. Add a constant to your project, and call it in the isMatch function instead of the string.