Table of contents (1) Their use in MusicBee (https://getmusicbee.com/forum/index.php?topic=38817.0#post_Title_1)
|
Function and syntax | Purpose | IF <tag> matches RegEx, returns: | ELSE, returns: |
$IsMatch(<tag>,RegEx) | checks if the RegEx is present anywhere in the tag | T | F |
$RxReplace(<tag>,RegEx,new) | global string replacement | <tag> content with each occurrence of RegEx replaced by the new replacement string | the unmodified <tag> content |
$RxMatch(<tag>,RegEx) | first matching portion | first portion of the tag matching the RegEx | a void string |
$RxSplit(<tag>,RegEx,n) | nth delimited section | nth section of the <tag> content split up by using RegEx as delimiter | the unmodified <tag> content |
Symbol | Meaning |
a | literal character 'a' All characters match themselves literally, except those having special meaning in a RegEx: . + * ? ^ $ ( ) [ ] { } | \ See also next table "(2c) Literal characters, backslashed (https://getmusicbee.com/forum/index.php?topic=38817.0#post_Title_2c)". |
[aeiou] | any character in the set |
[^aeiou] | any character not in the set |
[a-z] | any character in the range |
[^a-z] | any character not in the range |
. | any character, except new line |
[.] | character '.' |
\uFFFF | Unicode (utf16) character with hex. code 'FFFF' |
Symbol | Meaning |
\w | a word character: letter, digit, connector (hyphen, underscore) |
\W | a non-word character |
\d | a digit |
\D | a non-digit character |
\s | a white space character (including: space, tab, vertical tab, linefeed) |
\S | a non-space character |
\p{P} | any punctuation character, such as: . , ' ‘ " “ - - : ; |
\P{P} | any non-punctuation character |
\p{S} | any symbol character (currency, math, ...) |
\P{S} | any non-symbol character |
Symbol | Meaning |
\. \[ \] | The character after the backslash: . [ ] Meaning without \: see "(2a) Custom character classes (https://getmusicbee.com/forum/index.php?topic=38817.0#post_Title_2a)". |
\+ \* \? \{ \} | The character after the backslash: + * ? { } Meaning without \: see "(4a) Quantifiers (https://getmusicbee.com/forum/index.php?topic=38817.0#post_Title_4a)". |
\( \) \| | The character after the backslash: ( ) | Meaning without \: see "(3) Groups (https://getmusicbee.com/forum/index.php?topic=38817.0#post_Title_3)". |
\^ \$ | The character after the backslash: ^ $ Meaning without \: see "(4c) Anchors (https://getmusicbee.com/forum/index.php?topic=38817.0#post_Title_4c)". |
\\ | a backslash |
Symbol | Meaning |
foobar | literal string 'foobar' |
[a-z][0-9] | any letter, immediately followed by any digit => matches a3, b0, c9, … |
Symbol | Group type | Meaning |
(SubRegEx) | indexed group, capturing | Treats SubRegEx as a group and places the matching string in an indexed memory. Each group of the whole RegEx is assigned an incremented number, starting from 1. See "(3c) Substitutions (https://getmusicbee.com/forum/index.php?topic=38817.0#post_Title_3c)" below. |
(?:SubRegEx) | non-capturing group | Treats SubRegEx as a group, without placing the matching string in an indexed memory. Useful if you simply want to apply a quantifier to the group. |
(?<alias>SubRegEx) | named group, capturing | The matching string is stored in a named memory instead of an indexed one. See "(3c) Substitutions (https://getmusicbee.com/forum/index.php?topic=38817.0#post_Title_3c)" below. |
(choice1|choice2|...) | option group, capturing | Matches any of the choices, and stores the matching string in an indexed memory. Example: • (Bach|Mozart) matches 'Bach' and 'Mozart' |
(?:choice1|choice2|...) | option group, non-capturing | Matches any of the choices, without storing the matching string in an indexed memory. |
Symbol | Lookaround type | Meaning |
a(?=suffix) | positive lookahead | Matches 'a' followed by 'suffix', without including 'suffix' itself in the matching string. |
a(?!suffix) | negative lookahead | Matches 'a' not followed by 'suffix', without including 'suffix' itself in the matching string. |
(?<=prefix)a | positive lookbehind | Matches 'a' preceded by 'prefix', without including 'prefix' itself in the matching string. |
(?<!prefix)a | negative lookbehind | Matches 'a' not preceded by 'prefix', without including 'prefix' itself in the matching string. |
Symbol | Meaning | Example |
$n | indexed group n | $RxReplace(<MyTag>,"(.{3})(.{3})","$2,$1") -> 'Bar,Foo' |
$` | the substring before the match | $RxReplace(<MyTag>,"a","$`") -> 'FooBFooBr' |
$' | the substring after the match | $RxReplace(<MyTag>,"a","$'") -> 'FooBrr' |
$+ | the last indexed memory | $RxReplace(<MyTag>,"^(.{3})(.{3})(?:.*)$","$+") -> 'Bar' |
${alias} | the content of stored memory alias See: (?<alias>SubRegEx) in "(3) Groups (https://getmusicbee.com/forum/index.php?topic=38817.0#post_Title_3)" | $RxReplace(<MyTag>,"(?<First>.{3})(?<Second>.{3})","${Second}") -> 'Bar' |
$& | the matching string | $RxReplace(<MyTag>,"[aeiou]{2}","[$&]") -> 'F[oo]Bar' |
$_ | the whole input string | $RxReplace(<MyTag>,"[aeiou]{2}","[$_]") -> 'F[FooBar]Bar' |
Symbol | Meaning | Example |
\n | indexed group n | "(.)\1" matches a character followed by its repetition, such as: aa, bb, cc, … "(.)(.)\2\1" matches two characters followed by their repetition in mirror, such as: ABBA, elle, otto, ... |
\k<alias> | named group alias | "(?<one>.)\k<one>" matches a character followed by its repetition, such as: aa, bb, cc, … "(?<one>.)(?<two>.)\k<two>\k<one>" matches two characters followed by their repetition in mirror, such as: ABBA, elle, otto, … |
Symbol | Meaning | Example |
+ | one or more | ba+r matches: bar, baar, baaar, … but not: br |
? | zero or one | ba?r matches: br, bar but not: baar |
* | zero or more | ba*r matches: br, bar, baar, … |
{m,n} | between m and n times (both inclusive) | ba{2,3}r matches: baar, baaar |
{m,} | at least m times | ba{2,}r matches: baar, baaar, baaaar, … |
{0,n} | at most n times | ba{0,2}r matches: br, bar, baar |
Greedy | Lazy | Meaning |
+ | +? | one or more |
? | ?? | zero or one |
* | *? | zero or more |
{m,n} | {m,n}? | between m and n times (both inclusive) |
{m,} | {m,}? | at least m times |
{0,n} | {0,n}? | at most n times |
Symbol | Meaning | Example |
^ | at start of string | "^A" matches "A" at the beginning of a string |
$ | at end of string | "bee$" matches "bee" at the end of a string |
\b | on word boundary | "\bbee" matches words starting with bee, such as "beehive" "bee\b" matches words ending with bee, such as "MusicBee" |
\B | not on word boundary | "\Bbee\B" matches "bee" in "bumblebees" |
Symbol | Meaning | Example |
(?-i) | case-sensitive: applies to the RegEx part to its right | "(?-i)a" matches "a" but not "A" |
(?i) | case-insensitive: applies to the RegEx part to its right | "(?-i)a(?i)a" matches "aA" but not "AA" |
No regular expressions were harmed during the making of this post.Well, I'm not sure about that ;-)
This is impressive and beautifully done. A great addition to Tips & Tricks!A jong ;) , thanks for your kind words and your keen eye!
I learned some new things, and am surely going to make good use of a favorites shortcut for it.
(...)
7. Awesome work. I have thought about doing something like this also, but I wasn't up to the task and gave up on it, but I think you nailed it.
(...)
And I have some comments ;-) :
1. it should say 'not followed by...'Okee!
1b. And maybe add the terms: lookahead and lookbehind to that part?
(maybe give them their own 'Lookarounds' header, instead of having them under 'Groups'?)
2. + 3.There is (as often) more than one way to say it. I don't mind changing if you think it sounds clearer.
4. ma{2,3}n matches: maan, maaanThe suffixed n is not too much, since it's present in maan and maaan. Here, "a{2,3}" is both prefixed and suffixed.
has a leftover 'n' behind {2,3} that shouldn't be there
5. I believe those should be round brackets, not curly ones.Sure thing. And I feel relieved that the RegEx Welfare Society didn't suit me... :)
6. Not all of the above need to/should be escaped in that case, right?A first draft, since the answer is not obvious, as you mentioned:
The suffixed n is not too much, since it's present in maan and maaan. Here, "a{2,3}" is both prefixed and suffixed.Ah, my stupid hat must still have been on when I read that as a mistake, my brain registered the 'n' as representing a number. (and those are already between the brackets)
A first draft, since the answer is not obvious, as you mentioned:Yeah, it's not too obvious a matter. I think to recall that either an opening, or a closing straight bracket does need escaping, but the other doesn't.
between "[...]", I don't escape special characters except: [ ] -
But as for capturing groups in general, I'll check in my Perl bible and perform some tests.
"I'm not a number, I'm a free man!"That's what you think ;-)
i'm not sure that .net regexes supports for $_. there are many derivations of regex specs.It works, I tested before posting this.
* Unicode support: already considered when preparing the original post, I'll select the crème de la crème + external reference for those who wish extended documentation.I don't understand what you are saying here.
I don't understand what you are saying here.You could use a cuppa. :D I've just had one (Yes, weekend!)
(I'll take a drink, maybe that helps)
To rephrase my previous post: I'm going to prepare an addition about Unicode in RegExes. Stay tuned.Great. Especially the zero-width space can be useful for sorting purposes. (placing it at the beginning of a tag)
You could use a cuppa. :D I've just had one (Yes, weekend!)Hey!