This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision Next revision Both sides next revision | ||
Regular_Expressions [2019/02/03 10:52] ccstone [Online Primers & Tutorials] |
Regular_Expressions [2021/04/08 00:16] peternlewis [Capture Groups] |
||
---|---|---|---|
Line 27: | Line 27: | ||
^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:Search_using_Regular_Expression|Search using Regular Expression Action]] will return the _first_ match it finds in the source string.\\ In order to make it be a "global" search, you need to put this Action in a [[action:For_Each|For Each Action]] that uses the [ [[collection:Substrings_In|Substrings Matching in]] ] [[:Collections|Collection]]. This will loop through all matches found in the source string.\\ This is often indicated in other tools by the `/g` modifier.| |
|Case Insensitive|`(?i)`|Matching will be in a case-insensitive manner.\\ In some Actions this is NOT necessary since the Action already provides an "ignoring case" option.| | |Case Insensitive|`(?i)`|Matching will be in a case-insensitive manner.\\ In some Actions this is NOT necessary since the Action already provides an "ignoring case" option.| | ||
|Dot includes EOL|`(?s)`|A "`.`" in a pattern will match a line terminator in the input text. Note that a CR LF pair in text behave as a single line terminator, and will match a single "." in a RE pattern.| | |Dot includes EOL|`(?s)`|A "`.`" in a pattern will match a line terminator in the input text. Note that a CR LF pair in text behave as a single line terminator, and will match a single "." in a RE pattern.| | ||
Line 39: | Line 39: | ||
* Use the form of `$<CG#>`, or `\<CG#>` (in ver 8+) in the Action Replace box, where `<CG#>` is the number for the capture group. | * 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: | * 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 `\<CG#>` used in other apps/languages, like BBEdit. | * This is the same as `\<CG#>` used in other apps/languages, like BBEdit. | ||
+ | * The zeroth capture group (eg `$0`) is the entire match. | ||
For more information, see [[https://www.regular-expressions.info/brackets.html | Capture Groups]]. | For more information, see [[https://www.regular-expressions.info/brackets.html | Capture Groups]]. | ||
Line 138: | Line 141: | ||
==== Software ==== | ==== Software ==== | ||
- | - [[http://www.barebones.com/products/bbedit/|BBEdit (commercial) or BBEdit-Lite (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 ==== |