Regular_Expressions
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| Regular_Expressions [2020/09/27 03:42] – [Search Modifiers] Clarify the "Global" search modifier. JMichaelTX | Regular_Expressions [2026/10/08 02:41] (current) – peternlewis | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | {{: | ||
| ====== Regular Expressions (RegEx) ====== | ====== Regular Expressions (RegEx) ====== | ||
| - | + | Keyboard Maestro uses [[https://www.keyboardmaestro.com/action/linkthru? | |
| - | Keyboard Maestro uses [[http://userguide.icu-project.org/strings/regexp|ICU Regular Expressions]] (aka RegEx or RegExp) which is very similar to PCRE (Perl Compatible Regular Expressions), | + | |
| Line 19: | Line 17: | ||
| ===== Search Modifiers ===== | ===== Search Modifiers ===== | ||
| - | The ICU calls these modifiers | + | The ICU calls these modifiers [[https://www.keyboardmaestro.com/action/linkthru? |
| - | The search modifier " | ||
| - | For example: | ||
| - | `(? | ||
| - | as shown in the below example #1. | ||
| ^Purpose^Pattern to Use^Description^ | ^Purpose^Pattern to Use^Description^ | ||
| - | |Global|NONE|The [[action: | + | |Global|NONE|The [[action: |
| |Case Insensitive|`(? | |Case Insensitive|`(? | ||
| |Dot includes EOL|`(? | |Dot includes EOL|`(? | ||
| Line 33: | Line 27: | ||
| |Word Boundaries|`(? | |Word Boundaries|`(? | ||
| |Comments|`(? | |Comments|`(? | ||
| + | |||
| + | Note that matches are **case sensitive** by default (unless the action offers an //ignores case// option), so you can use (?i) to make the regular expression case insensitive. | ||
| + | |||
| + | The search modifier can apply to a section of the regular expression by using the form: | ||
| + | |||
| + | ``` | ||
| + | Case Sensitive (?i:case insensitive) Case Sensitive | ||
| + | ``` | ||
| + | |||
| + | of the search modifier can apply for the remainder of the pattern (unless changed later) like this: | ||
| + | |||
| + | ``` | ||
| + | Case Sensitive (?i)case insensitive case insensitive | ||
| + | ``` | ||
| + | |||
| + | or | ||
| + | |||
| + | ``` | ||
| + | Case Sensitive (?i)case insensitive (?-i) Case Sensitive | ||
| + | ``` | ||
| + | |||
| + | For example to search for the start of a line anywhere within the pattern, for the text "Hello THERE" where THERE is case insensitive you could use: | ||
| + | |||
| + | ``` | ||
| + | (? | ||
| + | ``` | ||
| + | |||
| + | Note that `(?…)` is not a Capture Group. | ||
| Line 39: | Line 61: | ||
| * Use the form of `$< | * Use the form of `$< | ||
| * Examples: | * Examples: | ||
| - | * `$1, $2, $3` | + | * `$1`, `$2`, `$23` |
| - | * `\1, \2, \3` | + | * `${1}`, ${2}`, ${23}`, |
| + | * `${name}` - named capture group (v9.2+, 10.13+) | ||
| + | * `\1`, `\2`, `\3` - single digit only (v8.0+) | ||
| * This is the same as `\< | * This is the same as `\< | ||
| + | * The zeroth capture group (eg `$0`) is the entire match. | ||
| For more information, | For more information, | ||
| Line 53: | Line 78: | ||
| ===== ICU 55+ Metacharacters ===== | ===== ICU 55+ Metacharacters ===== | ||
| - | For the currently complete list, see [ICU Regular Expression Metacharacters](http://userguide.icu-project.org/strings/regexp# | + | For the currently complete list, see [ICU Regular Expression Metacharacters](https://www.keyboardmaestro.com/action/linkthru? |
| - | + | ||
| - | **New Metacharacters Available in ICU 55+**(([ICU Regular Expression Metacharacters](http:// | + | |
| [ICU 55](http:// | [ICU 55](http:// | ||
| Line 63: | Line 86: | ||
| These Metacharacters offer some powerful solutions to long-standing RegEx problems. These can replace complicated RegEx patterns previously required, and are recommended for use if you are running the required versions. | These Metacharacters offer some powerful solutions to long-standing RegEx problems. These can replace complicated RegEx patterns previously required, and are recommended for use if you are running the required versions. | ||
| - | ^ New Metacharacters in ICU 55+(([ICU Regular Expression Metacharacters](http://userguide.icu-project.org/strings/regexp# | + | ^ New Metacharacters in ICU 55+(([ICU Regular Expression Metacharacters](https://www.keyboardmaestro.com/action/linkthru? |
| ^ Character ^ Alternate Expression\\ (Pre ICU 55) ^ Description ^ | ^ Character ^ Alternate Expression\\ (Pre ICU 55) ^ Description ^ | ||
| | `\h` | `[^\S\r\n\f]` | Match a Horizontal White Space character.\\ They are characters with Unicode General Category of Space_Separator plus the ASCII tab (\u0009). | | | `\h` | `[^\S\r\n\f]` | Match a Horizontal White Space character.\\ They are characters with Unicode General Category of Space_Separator plus the ASCII tab (\u0009). | | ||
| Line 82: | Line 105: | ||
| 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. | 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. | ||
| - | 1. Use the [[action: | + | 1. Use the [[action: |
| - | 2. Then use a [[action:Search_Variable|Search | + | 2. Then use a [[action:Search_using_Regular_Expression|Search |
| Both Actions can use the same RegEx pattern. | 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](https:// | + | |
| + | For a complete macro using this method, see: [MACRO: Get List of RegEx Capture Group of Multiple Matches](https:// | ||
| Line 132: | Line 155: | ||
| ==== General ==== | ==== General ==== | ||
| - | - [[http://userguide.icu-project.org/strings/regexp|ICU Regular Expressions]] | + | - [[https://www.keyboardmaestro.com/action/linkthru? |
| - [ICU Unicode Properties for Regular Expressions](http:// | - [ICU Unicode Properties for Regular Expressions](http:// | ||
| - [[https:// | - [[https:// | ||
| Line 164: | Line 187: | ||
| ==== Online Primers & Tutorials ==== | ==== Online Primers & Tutorials ==== | ||
| - | - [[http:// | ||
| - | - [[http:// | ||
| - [Regular Expressions Quick Start](http:// | - [Regular Expressions Quick Start](http:// | ||
| - [[http:// | - [[http:// | ||
| Keywords: | Keywords: | ||
Regular_Expressions.1601178151.txt.gz · Last modified: by JMichaelTX
