Regex java action for capturing group?

1
The goal I have for a regular expression is to retrieve the capturing groups from the regex into a list or object. for instance this Dutch postal code example https://regex101.com/r/fS4gQ7/1 In this case I want an object with the 2 values(the 4 digits and the 2 characters) in it so I can use these values for further processing. anayone want to share his java action which can do this?
asked
4 answers
0

You can validate string values against a regex in microflow too. Is there a specific reason why you wouldn't want to use the microflow expression?

 isMatch('3024EL', '([0-9]+)([a-zA-Z]+)')

This offers the same capability as the regex.matcher class in Java.

See documenation page: https://world.mendix.com/display/refguide5/String+function+calls#Stringfunctioncalls-isMatch

answered
0

I use IsMatch to validate but I want to capture the result of the match. in your example I want a list/object with 3024 and EL

answered
0

Thanks Ronald :) the way you describe is do-able for small regexes but the postal code was an example. With more complex regexes (with 11 groups) I prefer a java action

answered
-1

Why not just do a regular expression with some string breakup? First check the string with this regex: ^[1-9][0-9]{3}\s?[a-zA-Z]{2}$ found here. Then take a look at the string function calls First check the length of the string if it is 6 or 7 (with the length function). Then do a substring ($zipcode,0,4) then you should have the four first digits. If the string is 6 do a substring ($zipcode,4,2) otherwise ($zipcode,5,2). You can parse the four part back to a number with the parsestring function.

Regards,

Ronald

answered