Jump to content

Convert regexp named capture groups to vars


Recommended Posts

The "Replace" utility supports regexp matches. Complex extraction of string parts into vars could be supported using regular expression named capture groups, for example:

 

^(?<first>\w+)\s+(?<second>\w+)$

 

This regexp could create two variables "first" and "second" with the contents of the two named groups.

Link to comment
Share on other sites

Welcome @Annika,

 

It feels somewhat out of scope that the replace utility would also set variables. But it’s possible to get what you want by composing a few objects. In the example, you can replace the output with \1,\2 (tip: you can insert a literal newline with ⌥↵, to make it more resilient) then use a Split Argument to Variables Utility to make it into variables. You can take it one step further by connecting that to an Argument and Variables Utility to rename your newly-created sequential variables into something else.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...