The Search using Regular Expression action allows you to search a clipboard, variable, a file (v8+) or some text (v8+) for a regular expression and capture what you find to one or more variables. This can be very useful for splitting apart the contents of a variable.
Note: This RegEx Search returns only the first match in the source text.
If you want to process all matches, you will need to use a For Each Action as Shown in this Example.
Select the source to search to search using the Search pop-up. In all of the RegEx searches, you can choose to search in any one of the following: System Clipboard, Variable, File, Text entered into the Action, and Named Clipboard.
Select whether or not to match the case from the using Regular Expression pop-up. You can also use a RegEx flag at the beginning of the pattern to indicate case insensitive matching:
Then enter the RegEx pattern to search for in the text area.
Enter the Variable for each the entire Match and each Capture Group you wish to save as a Variable. This output section will auto-expand to present one field for each Capture Group in your RegEx pattern.
For more information, see Capture Groups.
If the search fails (no match), by default (7.1+) the action will abort the macro and notify you of the failure. The destination variables will not be modified. You can turn off aborting the macro and/or notifying you in the gear menu (the destination variables will still not be modified in this case).
1. Use a regular expression to search through a product price list and save only certain parts of it.
If your Source String (data) is:
SKU1234Δ Widget 1Δ $12.95
(the “Δ” character is a TAB character)
then you would use a RegEx pattern like:
To see a detailed explanation, and live editor, see https://regex101.com/r/MQ5FwG/1/.
Save the first and third bracketed items (Capture Groups) to save the SKU number and the price.
To work through a list you would need to include a loop or repeat of some kind.
Which results in: