Combine multiple regex pattern module into 1

Hey, I have an automation that uses multiple regex patterns to extract specific details such as name, date etc.

Is there a way I could combine all the regex pattern module into one?

The current one works perfectly but looks a bit cluttered

Here are the regex patterns used in each module

  1. ([^|\n]+) | ([^\s@]+@[^\s@]+) | (\d+)
  2. Location:\s(.+)
  3. Case Lead ID: #(.+)
  4. Case Description:\s±\s*(.+)

Hi @Fahad_Sheji ,

As a non-expert in Regex, I can try to help you. I think one way to do this is by combining all of the Regex pattern modules into one using the OR operator | and naming the groups to easily parse them afterwards.
If I remember correctly, Make will output the matches with their group name which makes it easier to get the right result afterwards.

Ref.: Groups and backreferences - JavaScript | MDN

Named capturing group: Matches “x” and stores it on the groups property of the returned matches under the name specified by <Name>. The angle brackets (< and >) are required for group name.
For example, to extract the United States area code from a phone number, we could use /\((?<area>\d\d\d)\)/. The resulting number would appear under matches.groups.area.

Glenn - Callinetic

1 Like

@Fahad_Sheji As @Callinetic said you can combine them with an OR and aggregate them at the end. Take a look at some of the other posts which explain this:

2 Likes

I have a scenario that does just that, using named capture groups.
Just add (?) to your group and you’ll end up having each named group as one variable – and you can have as many as needed in one single module.

If you provide a sample text I can try help you out with the Regex, but as you already have the code, it should be just a matter of adapt it (maybe marking each line start, for instance).

1 Like