Regular_Expressions
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| Regular_Expressions [2018/07/09 00:58] – [ICU 55+ Metacharacters] JMichaelTX | Regular_Expressions [2022/11/10 08:29] (current) – [Online Primers & Tutorials] ccstone | ||
|---|---|---|---|
| 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 16: | Line 14: | ||
| There are many Actions in Keyboard Maestro where you can use a regular expression, which may not be obvious. | There are many Actions in Keyboard Maestro where you can use a regular expression, which may not be obvious. | ||
| - | |||
| - | |||
| - | ---- | ||
| - | |||
| ===== Search Modifiers ===== | ===== Search Modifiers ===== | ||
| - | The ICU calls these modifiers "[[http://userguide.icu-project.org/strings/regexp# | + | The ICU calls these modifiers "[[https://www.keyboardmaestro.com/action/linkthru? |
| The search modifier " | The search modifier " | ||
| Line 31: | Line 25: | ||
| ^Purpose^Pattern to Use^Description^ | ^Purpose^Pattern to Use^Description^ | ||
| - | |Global|NONE|All searches are global in Keyboard Maestro.\\ This is often indicated in other tools by the `/g` modifier.| | + | |Global|NONE|The [[action: |
| |Case Insensitive|`(? | |Case Insensitive|`(? | ||
| |Dot includes EOL|`(? | |Dot includes EOL|`(? | ||
| Line 40: | Line 34: | ||
| ===== Capture Groups ===== | ===== Capture Groups ===== | ||
| + | |||
| * 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 54: | Line 51: | ||
| You can use Keyboard Maestro [[Tokens|Text Tokens]] anywhere appropriate in both the Search pattern and the Replace pattern. | You can use Keyboard Maestro [[Tokens|Text Tokens]] anywhere appropriate in both the Search pattern and the Replace pattern. | ||
| - | --- | ||
| ===== 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:// | ||
| * macOS 10.11+ (El Capitan) except for JavaScript | * macOS 10.11+ (El Capitan) except for JavaScript | ||
| - | * Keyboard Maestro | + | * Keyboard Maestro Native Actions |
| 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. | ||
| - | [FIXME: | + | ^ New Metacharacters in ICU 55+(([ICU Regular Expression Metacharacters](https://www.keyboardmaestro.com/action/linkthru? |
| - | + | ||
| - | ^ New Metacharacters in ICU 55+(([ICU Regular Expression Metacharacters](http://userguide.icu-project.org/strings/regexp# | + | |
| ^ 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). | | ||
| - | | `\H` | TBD | Match a non-Horizontal White Space character. | | + | | `\H` | `[\S\r\n\f]` |
| - | | `\k< | + | | `\k< |
| | `\R` | `(?: | | `\R` | `(?: | ||
| | `\v` | `[\n\r]` | Match a new line character.\\ The new line characters are \u000a, \u000b, \u000c, \u000d, \u0085, \u2028, \u2029.\\ Does not match the new line sequence CR LF. | | | `\v` | `[\n\r]` | Match a new line character.\\ The new line characters are \u000a, \u000b, \u000c, \u000d, \u0085, \u2028, \u2029.\\ Does not match the new line sequence CR LF. | | ||
| - | | `\V` | TBD | Match a non-new line character. | | + | | `\V` | `[^\n\r]` |
| - | + | For an in-depth discussion, see this Forum topic: [RegEx for Horizontal Whitespace](https:// | |
| - | --- | + | |
| ===== Examples ===== | ===== Examples ===== | ||
| Line 103: | Line 93: | ||
| ===== See also: ===== | ===== See also: ===== | ||
| - | |||
| - | ---- | ||
| === Actions === | === Actions === | ||
| Line 125: | Line 113: | ||
| * [[: | * [[: | ||
| - | ---- | ||
| ==== Macros That Use RegEx ==== | ==== Macros That Use RegEx ==== | ||
| Line 144: | Line 131: | ||
| ==== 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 150: | Line 137: | ||
| ==== Software ==== | ==== Software ==== | ||
| - | | + | |
| - | | + | * The commercial demo expires in 30 days and reverts to the still //very// powerful BBEdit-Lite (freeware). |
| - | | + | '''' |
| - | | + | |
| + | | ||
| + | | ||
| + | |||
| + | | ||
| + | |||
| + | * [[https:// | ||
| + | * [[http:// | ||
| ==== Books ==== | ==== Books ==== | ||
| Line 169: | Line 163: | ||
| ==== Online Primers & Tutorials ==== | ==== Online Primers & Tutorials ==== | ||
| - | - [[http:// | ||
| - | - [[http:// | ||
| - [Regular Expressions Quick Start](http:// | - [Regular Expressions Quick Start](http:// | ||
| - [[http:// | - [[http:// | ||
| - | - [[http:// | ||
| - | |||
| - | ---- | ||
| Keywords: | Keywords: | ||
Regular_Expressions.1531097918.txt.gz · Last modified: by JMichaelTX
