using Mendix regular expressions

I have some problems in working with regular expressions functions in mendix. I ahve to process many records which are structured in certain way. The strings come in 4 classes and they can be "right' or wrong (with errors) or better to call them well formed or not well formed. The well formed string in first class has the following structure (// only for illustration) //Voorzieningenrechter Zutphen 9 maart 2010 (Autotelex v Autotaxatie), LJN BL6854 (ECLI:NL:RBZUT:2010:BL6854) // So first I have to test if this input validates on the input structure, then I want the fields Online I use: (\D*)(\d+\D*\d{4})\s\((\D\*\))\,\s([L][J][N]\s\D\D\d{4})\s(\(.*\)) and I get automatic the matches: MATCH 1 1. [0-29] Voorzieningenrechter Zutphen [29-41] 9 maart 2010 [43-67] Autotelex v Autotaxatie) [69-79] LJN BL6854 [80-107] (ECLI:NL:RBZUT:2010:BL6854) and the result should be strings with f1:Voorzieningenrechter Zutphen (\D*) f2:9 maart 2010 f3: Autotelex v Autotaxatie f4: LJN BL6854 f5 ECLI:NL:RBZUT:2010:BL6854 Then when I use isMatch and ReplaceFirst I get stucked but I dont unerstand why, I test my regular expressions girst online What would be best code?
3 answers

You could work around it by using the substring function. Use the findfirst to find the first space or , and then use the substring to get parts of the string. This way you can use a regex on parts and hope that the ismatch works for that part.




EDIT: wrong answer

Update after testing: The behavior described below applies to community commons 'RegexReplaceAll' and 'RegexTest' (sorry, initial answer was wrong, but left this here for completeness / alternative)

After some testing: in general, with the build-in regex functions you should be able to take the regex literal, but put single quotes around them (single quotes themselves can be escaped by doubling them). Replacement strings seems to be taken always literal.

IsMatch needs to match the complete string before a match is made, for example '\d' does not match '1booyah', but, '\d.*' does.


For community commons regex functions:

The regexes you could use are any valid Java regexes (in most regex engines you can use a flavour). but please note that you need to enter your regular expression as string in Mendix (and java). So that means that after construction the regex, you need to put it between single quotes, and escape it (to make sure you can use single quotes in your regex).

So for example an regex like ^\w+$ needs to be entered in the microflow action as '^\\w+$' (note the double slash and the quotes). So basically, doubling all the forward slashes in your expression does the trick.

replacement strings are allowed to contain back references to the regular expression match, and as such might contain special characters that need special escapes (dollar and forward slash to be specifically).


Hi Arthur,

See my post, i also had issues with regular expressions matching online testers ie:, but not in Mendix. I think there is a bug or its being interpreted incorrectly. See my post below.

Maybe somebody from Mendix can have a closer look at what is happening with regex and the isMatch function.