Why is the Regex expression not matching accordingly?

0
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.
asked
2 answers
3

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.

answered
1

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.

answered