User Tools

Site Tools


Regular_Expressions

**This is an old revision of the document!**

Regular Expressions (RegEx)

Keyboard Maestro uses ICU Regular Expressions (aka RegEx or RegExp) which is very similar to PCRE (Perl Compatible Regular Expressions), and you can read their documentation by choosing ICU Regular Expression Reference from the Help menu in Keyboard Maestro.

In Keyboard Maestro actions, if it uses the term “matches” is means a regular expression.

Please pardon the dust while we work to build this page for you. 8-)

Info to consider for inclusion here (in no order, numbered for easy reference)

  1. All Keyboard Maestro Search and Replace actions are global by default. This is often indicated in other tools by the /g modifier.
  2. The (?m) modifier at the beginning of the Regular Expression in can be used to match the start of multiple lines.
    - The ICU calls these modifiers “flag options”.
  3. Use $1, $2, $3 etc for replacing with captured groups.
  4. You can use text tokens in the fields.

Examples

Example #1: Remove all line numbers from a string with multiple lines

Example #2: Extract Capture Group for Multiple Matches to Multiple Lines in a Variable

Sometimes you may need to extract a RegEx Capture Group after a match is made, and do this for multiple lines (matches) in the entire source string. To achieve this, you need to:

  1. Use the For Each Action to get each match into a variable (MatchString)
  2. Then use a Search Variable Action to get the Capture Group for that match

Both Actions can use the same RegEx pattern.


For a complete macro using this method, see:
MACRO: Get List of RegEx Capture Group of Multiple Matches


See also:

Documentation

Macros That Use RegEx

Forum

General

Software

Books

Online References

Online Primers & Tutorials


Keywords: Regular Expression, RegEx, RegExp, Find, Replace, Match

Regular_Expressions.1457167962.txt.gz · Last modified: 2016/03/05 03:52 by AlainLifchitz