⚠️ NOTE: If you have any questions regarding the content presented below, feel free to post them here. I will be happy to help anyway I can! Regex is a big passion of mine and I look forward to hearing from you. 😁

You can use capture groups save to memory a segment within parentheses and assign a variable to it. Starting at 1 and incrementing.
Example: Capture Groups
Below would result in it saving http://
to variable $1 and some-url.com
to variable $2.
- Source =~
http://some-url.com
- Regex =~
(http://)([\w.-]+)\b
- $1 =~
http://
- $2 =~
some-url.com
You can use capture groups for ‘back references’ as well. The variable values can be called/interpolated with #
.
Example: Back References
A non capture group is used for grouping without capturing it to a variable. To invoke a non-capture group you can use. =~ (?: )
.
Non capturing groups can be used to organize atoms together.
(?:what){2,}
=~ matches 2 or more whats. Example: whatwhat
or whatwhatwhatwhat
or whatwhatwhatwhatwhat
etc…!
Example:

mOAR