User Tools

Site Tools


Regular_Expressions

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Next revision Both sides next revision
Regular_Expressions [2016/08/03 12:53]
alain add forum link
Regular_Expressions [2019/02/03 11:16]
ccstone [Software]
Line 6: Line 6:
  
  
-In Keyboard Maestro actions, if it uses the term "​matches"​ is means a regular expression.+In any [[Actions|Action]] where the term "​matches"​ is used, you may (optionally) use a regular expression.
  
  
-{{:work-in-progress.png?200|}} +**The two most commonly used RegEx Actions are:** 
-Please pardon the dust while we work to build this page for you.  ​8-)+  * [[action:​Search_using_Regular_Expression|Search using Regular Expression ]] to extract [[https://​www.regular-expressions.info/​brackets.html ​Capture Groups]]. 
 +  * [[action:​Search_and_Replace|Search and Replace]]
  
-===== Capture Groups ===== +In all of the RegEx searchesyou can choose to search in any one of the followingSystem ClipboardVariableFile, Text entered into the Action, and Named Clipboard.
- +
-  - Use the form of `$n` in the Action Replace boxwhere n is the number for the capture group.  +
-  - Example`$1$2$3` +
-  - This is the same as `\n` used in other apps/​languages.+
  
 +There are many Actions in Keyboard Maestro where you can use a regular expression, which may not be obvious. ​ For more info see [Places where Regular Expressions can be used](https://​forum.keyboardmaestro.com/​t/​places-where-regular-expressions-can-be-used/​4392).
  
 ===== Search Modifiers ===== ===== Search Modifiers =====
Line 35: Line 33:
 |Word Boundaries|`(?​w)`|Controls the behavior of \b in a pattern.\\ If used, word boundaries are found according to the definitions of word found in [[http://​unicode.org/​reports/​tr29/#​Word_Boundaries|Unicode UAX 29, Text Boundaries]].| |Word Boundaries|`(?​w)`|Controls the behavior of \b in a pattern.\\ If used, word boundaries are found according to the definitions of word found in [[http://​unicode.org/​reports/​tr29/#​Word_Boundaries|Unicode UAX 29, Text Boundaries]].|
 |Comments|`(?​x)`|Ignores white space and allows #​comments.\\ If used, white space within regular expressions is ignored and you can use #​line-comments.| |Comments|`(?​x)`|Ignores white space and allows #​comments.\\ If used, white space within regular expressions is ignored and you can use #​line-comments.|
 +
 +
 +===== Capture Groups =====
 +
 +  * Use the form of `$<​CG#>​`,​ or `\<​CG#>​` (in ver 8+) in the Action Replace box, where `<​CG#>​` is the number for the capture group. ​
 +  * Examples: ​
 +    * `$1, $2, $3`
 +    * `\1, \2, \3`
 +  * This is the same as `\<​CG#>​` used in other apps/​languages,​ like BBEdit.
 +
 +For more information,​ see [[https://​www.regular-expressions.info/​brackets.html | Capture Groups]].
 +
  
 ===== Use of Text Tokens ===== ===== Use of Text Tokens =====
Line 40: Line 50:
 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 =====
 +
 +For the currently complete list, see [ICU Regular Expression Metacharacters](http://​userguide.icu-project.org/​strings/​regexp#​TOC-Regular-Expression-Metacharacters).
 +
 +**New Metacharacters Available in ICU 55+**(([ICU Regular Expression Metacharacters](http://​userguide.icu-project.org/​strings/​regexp#​TOC-Regular-Expression-Metacharacters)))
 +
 +[ICU 55](http://​site.icu-project.org/​download/​55) was released on 2015-04-01, and is available in the follow software versions:
 +  * macOS 10.11+ (El Capitan) except for JavaScript
 +  * 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. ​ For example, `\h` and `\R`.  ICU 55 is _not_ available in all RegEx engines. ​ A notable exception is JavaScript (and JXA), even in High Sierra. ​ So if you are using the native Keyboard Maestro Actions that use RegEx, it would be available, but not necessarily in Actions that use Execute Script in another language. ​ It is available in Execute AppleScript Actions that use ASObjC RegEx.
 +
 +^   New Metacharacters in ICU 55+(([ICU Regular Expression Metacharacters](http://​userguide.icu-project.org/​strings/​regexp#​TOC-Regular-Expression-Metacharacters))) ​  ^^^
 +^ 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 non-Horizontal White Space character. |
 +| `\k<​name>​` | //No Alternative//​ | Named Capture Back Reference. |
 +| `\R` | `(?:​\r?​\n|\r)` | Match a new line character, or the sequence CR LF.\\ The new line characters are \u000a, \u000b, \u000c, \u000d, \u0085, \u2028, \u2029 |
 +| `\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 non-new line character. |
 +For an in-depth discussion, see this Forum topic: [RegEx for Horizontal Whitespace](https://​forum.keyboardmaestro.com/​t/​wiki-update-regex-icu-55-metacharacters/​10788).
 ===== Examples ===== ===== Examples =====
  
Line 62: Line 94:
  
 ===== See also: ===== ===== See also: =====
- 
----- 
  
 === Actions === === Actions ===
Line 84: Line 114:
 * [[:​Triggers|See all Triggers]] * [[:​Triggers|See all Triggers]]
  
----- 
  
 ==== Macros That Use RegEx ==== ==== Macros That Use RegEx ====
Line 96: Line 125:
 - [[https://​forum.keyboardmaestro.com/​t/​how-to-search-and-replace-for-characters-in-variables/​3078/​11|How to search and replace for characters in variables]] - [[https://​forum.keyboardmaestro.com/​t/​how-to-search-and-replace-for-characters-in-variables/​3078/​11|How to search and replace for characters in variables]]
 - [[https://​forum.keyboardmaestro.com/​t/​cleaning-up-variables-at-the-end-of-sub-macros/​4561/​38|Cleaning Up Variables at the end of sub-macros]] - [[https://​forum.keyboardmaestro.com/​t/​cleaning-up-variables-at-the-end-of-sub-macros/​4561/​38|Cleaning Up Variables at the end of sub-macros]]
 +- [[https://​forum.keyboardmaestro.com/​t/​example-switch-action-with-or-conditions-copy-and-paste-regular-expressions/​4595|EXAMPLE:​ SWITCH action with "​OR"​ conditions (copy-and-paste regular expressions)]]
  
  
-- [[https://www.google.fr/​search?​q=site:​forum.keyboardmaestro.com+Regular+Expression+RegEx|Keyboard Maestro Forum topics about Regular Expressions (RegEx)]]+- [[https://​forum.keyboardmaestro.com/tags/regex|Keyboard Maestro Forum topics about Regular Expressions (RegEx)]]
  
 ==== General ==== ==== General ====
Line 108: Line 138:
 ==== Software ==== ==== Software ====
  
-  ​[[http://​www.barebones.com/​products/​textwrangler/|TextWrangler (a freeware text editor ​with PCRE regular expression support)]] +  ​[[http://​www.barebones.com/​products/​bbedit/|BBEdit]] -- A Programming Editor ​with PCRE regular expression support.      
-  ​[[http://​itunes.apple.com/​us/​app/​patterns-the-regex-app/​id429449079?​mt=12|Patterns ​— a regular expression analyzer on the app-store]] +    * The commercial demo expires in 30 days and reverts to the still //very// powerful BBEdit-Lite (freeware)
-  ​[[https://​itunes.apple.com/​us/​app/​regexrx/​id498370702?​mt=12|RegExRX ​— a regular expression analyzer on the app-store]] +''''​ 
-  ​[[https://​regex101.com|RegEx101.com]] -- Online RegEx Analyzer+ 
 +  ​[[http://​itunes.apple.com/​us/​app/​patterns-the-regex-app/​id429449079?​mt=12|Patterns]] -- A regular expression analyzer ​available ​on the app-store. 
 +  ​[[https://​itunes.apple.com/​us/​app/​regexrx/​id498370702?​mt=12|RegExRX]] -- A regular expression analyzer ​available ​on the app-store
 + 
 +  ​''''​ 
 + 
 +  * [[https://​regex101.com|RegEx101.com]] -- An Outstanding and Comprehensive ​Online RegEx Analyzer
 +  * [[http://​regexr.com/​|Regexr]] -- Regex testing and explaining, examples and references.
  
 ==== Books ==== ==== Books ====
Line 129: Line 166:
   - [[http://​www.agillo.net/​regex-primer-part-1/​|Regex Primer : Part 1]]   - [[http://​www.agillo.net/​regex-primer-part-1/​|Regex Primer : Part 1]]
   - [[http://​www.agillo.net/​regex-primer-part-2/​|Regex Primer : Part 2]]   - [[http://​www.agillo.net/​regex-primer-part-2/​|Regex Primer : Part 2]]
 +  - [Regular Expressions Quick Start](http://​www.regular-expressions.info/​quickstart.html)
   - [[http://​www.codeproject.com/​KB/​dotnet/​regextutorial.aspx|CodeProject.com RegExTutorial]]   - [[http://​www.codeproject.com/​KB/​dotnet/​regextutorial.aspx|CodeProject.com RegExTutorial]]
- 
- 
----- 
  
 Keywords: ​ //Regular Expression, RegEx, RegExp, Find, Replace, Match// Keywords: ​ //Regular Expression, RegEx, RegExp, Find, Replace, Match//
Regular_Expressions.txt · Last modified: 2022/11/10 03:29 by ccstone