KeyRoutines
StepFreetext.extract

Find text with a pattern and pull out what matches

Find with a pattern searches text with a regular expression and hands back what it found. It's how routines pull a code, a number or a link out of a longer piece of text.

How it works

  • Give it the text and the pattern; turn on All to get every match instead of just the first.
  • Advanced options keep only one group of the first match, by number or name, and ignore upper and lower case.
  • It returns the match, the list of matches, a count and whether anything was found; no match is not an error.
  • Each pattern search is limited to 100 milliseconds, so a runaway pattern fails instead of hanging.

Routines that use it

Order number from mail

Get the clipboard, find a pattern like a 6-digit number and type it with Type text.

All links

Find every web address in a text file read with Read text file and open them with Open URLs.

Window title part

On Window title changed, extract the song name and show it in a banner.

Settings

SettingWhat it does
TextThe text to search.
PatternA regular expression, such as \\d+ for a number or [\\w.]+@[\\w.]+ for an email address.
AllFind every match, not just the first.
GroupadvancedOnly keep one group of the first match: its number (1, 2…) or its name.
Ignore caseadvancedIgnore upper and lower case.

Good to know

  • Uses regular expressions, which take some learning.
  • Each search has a 100 millisecond limit.

Questions

Does KeyRoutines support regex?
Yes. Find with a pattern and Replace text both take regular expressions, and Compare values has a matches test.
What happens if nothing matches?
The step still succeeds and its found result is false, so you can check it with an If.

Pairs well with

Build this routine in KeyRoutines

Free from the Microsoft Store for Windows 11 and 10. Pro is a one-time upgrade.