MrC-temp: Difference between revisions
mNo edit summary |
mNo edit summary |
||
Line 27: | Line 27: | ||
The examples in this section use one of the modes from 1 through 9, to output the specified capture. |
The examples in this section use one of the modes from 1 through 9, to output the specified capture. |
||
'''<span style="font-family: Consolas, monospace;"><nowiki> |
|||
Regex([Name], /#(Big.*Man)#/, 1) |
|||
</nowiki></span>''' |
|||
''Matches track names that contain'' '''Big''' ''followed by'' '''Man''''', with anything (including nothing) in between, and outputs the matched tracks.'' |
''Matches track names that contain'' '''Big''' ''followed by'' '''Man''''', with anything (including nothing) in between, and outputs the matched tracks.'' |
||
Sample output: |
Sample output: |
||
:Big Butter and Egg Man |
:Big Butter and Egg Man |
||
:Big Man |
:Big Man |
||
:Big Manager |
:Big Manager |
||
:It's a Bigman Thing |
:It's a Bigman Thing |
||
'''<span style="font-family: Consolas, monospace;"><nowiki> |
|||
⚫ | |||
</nowiki></span>''' |
|||
''Matches against the Artist field and returns items that contain an opening (left) parenthesis followed by additional characters until the end of the artist string. Only the sub-string from any opening parenthesis until the end of the string will be returned, since this is the only captured portion.'' |
|||
Sample output: |
Sample output: |
||
:(Brian Eno/U2) |
:(Brian Eno/U2) |
||
:(feat. DJ Cam) |
:(feat. DJ Cam) |
||
:(Otis Day & The Knights) |
:(Otis Day & The Knights) |
||
:(w/Emmylou Harris) |
:(w/Emmylou Harris) |
||
⚫ | |||
'''<span style="font-family: Consolas, monospace;"><nowiki> |
|||
Regex([Name], /#([(][^)]+)$#/, 1) |
|||
</nowiki></span>''' |
|||
⚫ | |||
Sample output: |
Sample output: |
||
:(feat. David Bowie |
:(feat. David Bowie |
||
---- |
---- |
||
Line 54: | Line 67: | ||
The examples in this section use mode 0, to test if a string matches or not. The result of the test may be used to drive a conditional statement such as an if() statement. |
The examples in this section use mode 0, to test if a string matches or not. The result of the test may be used to drive a conditional statement such as an if() statement. |
||
'''<span style="font-family: Consolas, monospace;"><nowiki> |
|||
⚫ | |||
if(Regex([Artist],/#([[:punct:]])#/, 0),[R1] --> [Artist], No Punctuation) |
|||
</nowiki></span>''' |
|||
⚫ | ''Matches against the Artist field looking for any punctuation character. The results of the Regex() expression will be a 0 (false) or 1 (true) since the mode is set to 0, The true side of the if() test is set to output the first (and only) capture, which is expressed as [R1], and is followed by the string " --> " and then the artist name. In the false case, the string "No Punctuation" is output.'' |
||
Sample output: |
Sample output: |
||
:" --> Clarence "Frogman" Henry |
: " --> Clarence "Frogman" Henry |
||
:& --> Al Cohn & Zoot Sims |
: & --> Al Cohn & Zoot Sims |
||
:. --> Dr. John |
: . --> Dr. John |
||
:/ --> Bootsy Collins/Fatboy Slim |
: / --> Bootsy Collins/Fatboy Slim |
||
⚫ | |||
'''<span style="font-family: Consolas, monospace;"><nowiki> |
|||
⚫ | |||
listbuild(1, \, if(Regex([Artist],/#([[:punct:]])#/, 0), Contains Punctuation\[R1], No Punctuation), [Artist])&DataType=[list] |
|||
⚫ | |||
</nowiki></span>''' |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
: → No Punctuation |
: → No Punctuation |
||
<br>'''<nowiki>listbuild(1, \, if(Regex([Artist],/#([[:punct:]])#/, 0), Contains Punctuation\[R1], No Punctuation), [Artist])&DataType=[list]</nowiki>'''<br>''Similar to the previous example, but when used inside an expression column, builds an expandable tree with headings Contains Punctuation or No Punctuation, thus reducing the excessive number of entries that would be produced.'' |
|||
'''<div style="font-family: Consolas, monospace;"><nowiki> |
|||
A more complex example that removes semicolon and backslash characters, which cause problems when building a list... |
|||
if(Regex([Artist], /#([[:punct:]])#/, 0), |
|||
<pre> |
|||
</nowiki><br /> |
|||
⚫ | |||
Contains Punctuation\replace(replace([R1], ;,Semicolon), \, Backslash), |
: '''<nowiki> Contains Punctuation\replace(replace([R1], ;,Semicolon), \, Backslash), |
||
</nowiki><br /> |
|||
No Punctuation)\replace(replace([Artist], ;, / and/ ), \, //)&DataType=[list] |
: '''<nowiki> No Punctuation)\replace(replace([Artist], ;, / and/ ), \, //)&DataType=[list] |
||
</pre> |
|||
</nowiki></div>''' |
|||
''A more complex example, when used inside an expression column, builds an expandable tree with headings Contains Punctuation and No Punctuation that group artists based on whether or not their names contain any punctuation characters. Because semicolon and backslash are list separator characters for the expression language, for the example expression to work properly, these must be replaced (otherwise the list will not build as desired). In the list of punctuation, both backslash and semicolon characters have been replaced with their English equivalent words. In artist names, a semicolon is often used as a separator between the main artist and featured artists, so the expression replaces semicolons within an artist name with the word "and". Likewise, backslashes have been replaced with forward slashes.'' |
|||
---- |
---- |
||
Line 85: | Line 109: | ||
The examples in this section use mode -1, which cause Regex() to suppress output. This mode is only useful with captures, where the captures are utilized in subsequent portions of an expression. |
The examples in this section use mode -1, which cause Regex() to suppress output. This mode is only useful with captures, where the captures are utilized in subsequent portions of an expression. |
||
'''<span style="font-family: Consolas, monospace;"><nowiki> |
|||
Regex([Name], /#(\d{1,2})\.(\d{1,2}).(\d{4})#/, -1)[R3]//[R1]//[R2] |
|||
</nowiki></span>''' |
|||
''Matches and captures a date formatted as dd.mm.yyyy anywhere within a filename, and rearranges it in a standard format of yyyy/mm/dd. Since '''Mode''' is set to -1, no output occurs. However, captured match segments are made available for subsequent use. The three captures, [R1], [R2] and [R3] are arranged in the textual output such that the year, month and day ordering are as desired. |
''Matches and captures a date formatted as dd.mm.yyyy anywhere within a filename, and rearranges it in a standard format of yyyy/mm/dd. Since '''Mode''' is set to -1, no output occurs. However, captured match segments are made available for subsequent use. The three captures, [R1], [R2] and [R3] are arranged in the textual output such that the year, month and day ordering are as desired. |
||
: 2011/08/19 |
: 2011/08/19 |
||
: 2009/01/22 |
: 2009/01/22 |
||
... IN PROGRESS ... |
... IN PROGRESS ... |
Revision as of 16:51, 28 August 2011
Note: The File Properties page is now at its permanent home ==> File_Properties_(tags)
Note: This is MrC's working space for Wiki page work-in-progress.
Regex(...): Regular expression pattern matching
Regex() | This function performs regular expression (RE) pattern matching on its input. It can be used in one of three different modes: a test mode to test for a match, a capture output mode to output the specified captured pattern, and a silent, capture-only mode. All match captures are placed into special variables referenced as [R1], [R2], ... [R9], which can be used in subsequent expressions. The contents of the captures [R1] ... [R9] are available until the entire expression completes, or Regex() is run again, whereby they are replaced. (Available since build 16.0.155.) |
---|---|
Construction | Regex(String to test, Regular expression, Mode, Case sensitivity)
|
Examples | Examples: Modes 1 to 9
The examples in this section use one of the modes from 1 through 9, to output the specified capture. Regex([Name], /#(Big.*Man)#/, 1) Matches track names that contain Big followed by Man, with anything (including nothing) in between, and outputs the matched tracks. Sample output:
Matches against the Artist field and returns items that contain an opening (left) parenthesis followed by additional characters until the end of the artist string. Only the sub-string from any opening parenthesis until the end of the string will be returned, since this is the only captured portion. Sample output:
Similar to the previous example, but matches track names that contain a opening (left) parenthesis, but are missing the closing (right) parentheses through the end of the track name. This might be useful to help detect tagging inconsistencies Sample output:
Examples: Mode 0 The examples in this section use mode 0, to test if a string matches or not. The result of the test may be used to drive a conditional statement such as an if() statement. if(Regex([Artist],/#([[:punct:]])#/, 0),[R1] --> [Artist], No Punctuation) Matches against the Artist field looking for any punctuation character. The results of the Regex() expression will be a 0 (false) or 1 (true) since the mode is set to 0, The true side of the if() test is set to output the first (and only) capture, which is expressed as [R1], and is followed by the string " --> " and then the artist name. In the false case, the string "No Punctuation" is output. Sample output:
Similar to the previous example, but when used inside an expression column, builds an expandable tree with headings Contains Punctuation or No Punctuation, thus reducing the excessive number of entries that would be produced.
if(Regex([Artist], /#([[:punct:]])#/, 0),
A more complex example, when used inside an expression column, builds an expandable tree with headings Contains Punctuation and No Punctuation that group artists based on whether or not their names contain any punctuation characters. Because semicolon and backslash are list separator characters for the expression language, for the example expression to work properly, these must be replaced (otherwise the list will not build as desired). In the list of punctuation, both backslash and semicolon characters have been replaced with their English equivalent words. In artist names, a semicolon is often used as a separator between the main artist and featured artists, so the expression replaces semicolons within an artist name with the word "and". Likewise, backslashes have been replaced with forward slashes. Examples: Mode -1 The examples in this section use mode -1, which cause Regex() to suppress output. This mode is only useful with captures, where the captures are utilized in subsequent portions of an expression. Regex([Name], /#(\d{1,2})\.(\d{1,2}).(\d{4})#/, -1)[R3]//[R1]//[R2] Matches and captures a date formatted as dd.mm.yyyy anywhere within a filename, and rearranges it in a standard format of yyyy/mm/dd. Since Mode is set to -1, no output occurs. However, captured match segments are made available for subsequent use. The three captures, [R1], [R2] and [R3] are arranged in the textual output such that the year, month and day ordering are as desired.
|