Active patterns make using a Regex in F# neat: The matched groups are returned in the list after the pattern. Here is an example from our codebase:
Pattern found at Active Patterns – F# | Microsoft Learn:
In this example, I use the regex active pattern to map JSON parsing errors to a Result with typed error results. They are later mapped to HTTP status codes and error messages.
This also works for multiple catch groups:
[…] Today’s random F# code: Regex Active Pattern in API Validation (Urs Enzler) […]