MrC-temp: Difference between revisions

From wiki.jriver.com
Jump to navigation Jump to search
mNo edit summary
mNo edit summary
Line 16: Line 16:
* '''Mode''': ''Sets the mode in which Regex() will run. Optional, defaults to 0.''
* '''Mode''': ''Sets the mode in which Regex() will run. Optional, defaults to 0.''
** '''0''': ''Runs in test mode, returning 1 or 0, indicating whether the string matched (1) or did not match (0) the pattern. This mode is useful within an '''if()''' test, so that different true (1) or false (0) actions may be taken. There is no output in this mode. This mode is the default.''
** '''0''': ''Runs in test mode, returning 1 or 0, indicating whether the string matched (1) or did not match (0) the pattern. This mode is useful within an '''if()''' test, so that different true (1) or false (0) actions may be taken. There is no output in this mode. This mode is the default.''
** '''1''' - '''9''': ''Outputs the specified N<sup>th</sup> capture group's contents, where N ranges from 1 to 9. Currently, only a single capture is output in this mode, but all captures are available in the [R1] ... [R9] capture variables. This mode is used to easily output a single matching sub-string.''
** '''1''' to '''9''': ''Outputs the specified N<sup>th</sup> capture group's contents, where N ranges from 1 to 9. Currently, only a single capture is output in this mode, but all captures are available in the [R1] ... [R9] capture variables. This mode is used to easily output a single matching sub-string.''
** '''-1''': ''Runs in silent mode, with no output. This mode is useful as a means to capture portions of the string, and later use those captures in subsequent portions of an expression.''
** '''-1''': ''Runs in silent mode, with no output. This mode is useful as a means to capture portions of the string, and later use those captures in subsequent portions of an expression.''
* '''Case sensitivity''': ''Toggles the case-sensitivity of regular expressions. Optional, defaults to 0, ignoring case. To use this option, a value or comma-placeholder must also be set for the'' '''Mode''' ''option.''
* '''Case sensitivity''': ''Toggles the case-sensitivity of regular expressions. Optional, defaults to 0, ignoring case. To use this option, a value or comma-placeholder must also be set for the'' '''Mode''' ''option.''
Line 23: Line 23:
|- valign="top"
|- valign="top"
! scope="row" style="background: #A8E4A0; color: black; border: 1px solid black;" | Examples
! scope="row" style="background: #A8E4A0; color: black; border: 1px solid black;" | Examples
|style="background: #ecfeea; color: black; border: 1px solid black" | '''Regex([Name], /#(Big.*Man)#/, 1)'''<br>''Matches track names that contain'' '''Big''' ''followed by'' '''Man''''', with anything (including nothing) in between, and outputs the matched tracks.''
|style="background: #ecfeea; color: black; border: 1px solid black" | '''Examples using Modes = 1 to 9'''<br />

'''Regex([Name], /#(Big.*Man)#/, 1)'''<br />
''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<br />
:Big Butter and Egg Man<br />
Line 30: Line 33:
:It's a Bigman Thing<br />
:It's a Bigman Thing<br />


<br>'''Regex([Artist], /#([(].+)$#/, 1)'''<br>''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.''
'''Regex([Artist], /#([(].+)$#/, 1)'''<br>''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:
Line 38: Line 41:
:(w/Emmylou Harris)
:(w/Emmylou Harris)


<br>'''Regex([Name], /#([(][^)]+)$#/, 1)'''<br>''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''
'''Regex([Name], /#([(][^)]+)$#/, 1)'''<br>''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:
Sample output:
:(feat. David Bowie<br />
:(feat. David Bowie<br />


----
<br>'''if(Regex([Artist],/#([<nowiki>[:punct:]]</nowiki>)#/, 0),[R1] --> [Artist],No Punctuation)'''<br>''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.''

'''Examples using Mode = 0'''

'''if(Regex([Artist],/#([<nowiki>[:punct:]]</nowiki>)#/, 0),[R1] --> [Artist],No Punctuation)'''<br>''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:
Line 68: Line 75:
No Punctuation)\replace(replace([Artist], ;, / and/ ), \, //)&DataType=[list]
No Punctuation)\replace(replace([Artist], ;, / and/ ), \, //)&DataType=[list]
</pre>
</pre>

... IN PROGRESS...
----
'''Examples using Mode = -1'''

'''Regex([Name], /#(\d{1,2})\.(\d{1,2}).(\d{4})#/, -1)[R3]//[R1]//[R2]</nowiki>'''<br />
''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
: 2009/01/22

... IN PROGRESS ...


|}
|}

Revision as of 06:46, 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)
  • String to test: One or more library fields, plain text, or a combination of both, which is used as the string evaluated for a match.
  • Regular expression: This is the regular expression pattern used to perform matches and captures on the String to test.
    The regular expression language assigns special meaning to many characters. A few of these meta-characters, such as forward slash "/", comma "," and parenthesis "(" and ")", are also used by the Media Center expression language. To force the Media Center expression engine to ignore the meta-characters in regular expressions, surround the entire regular expression with /# and #/. This is Media Center's form of escapement, which tells the expression engine to ignore everything inside, so that the entire, uninterpreted regular expression can be provided to the Regex() regular expression evaluator. Although /# and #/ is not necessary when no conflicting characters are in use, and you may manually escape such characters with a forward slash "/", it is best practice to always encase a regular expression in /# and #/.
  • Mode: Sets the mode in which Regex() will run. Optional, defaults to 0.
    • 0: Runs in test mode, returning 1 or 0, indicating whether the string matched (1) or did not match (0) the pattern. This mode is useful within an if() test, so that different true (1) or false (0) actions may be taken. There is no output in this mode. This mode is the default.
    • 1 to 9: Outputs the specified Nth capture group's contents, where N ranges from 1 to 9. Currently, only a single capture is output in this mode, but all captures are available in the [R1] ... [R9] capture variables. This mode is used to easily output a single matching sub-string.
    • -1: Runs in silent mode, with no output. This mode is useful as a means to capture portions of the string, and later use those captures in subsequent portions of an expression.
  • Case sensitivity: Toggles the case-sensitivity of regular expressions. Optional, defaults to 0, ignoring case. To use this option, a value or comma-placeholder must also be set for the Mode option.
    • 0: Ignore case when matching (e.g. the letters E and e are identical). This is the default.
    • 1: Consider case when matching (e.g. the letters E and e are considered different).
Examples Examples using Modes = 1 to 9

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:

Big Butter and Egg Man
Big Man
Big Manager
It's a Bigman Thing

Regex([Artist], /#([(].+)$#/, 1)
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:

(Brian Eno/U2)
(feat. DJ Cam)
(Otis Day & The Knights)
(w/Emmylou Harris)

Regex([Name], /#([(][^)]+)$#/, 1)
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:

(feat. David Bowie

Examples using Mode = 0

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:

"  --> Clarence "Frogman" Henry
& --> Al Cohn & Zoot Sims
.  --> Dr. John
/  --> Bootsy Collins/Fatboy Slim


listbuild(1, \, if(Regex([Artist],/#([[:punct:]])#/, 0), Contains Punctuation\[R1], No Punctuation), [Artist])&DataType=[list]
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.

→ Contains Punctuation
→ $
Payola$
→ +
→ :
→ No Punctuation


listbuild(1, \, if(Regex([Artist],/#([[:punct:]])#/, 0), Contains Punctuation\[R1], No Punctuation), [Artist])&DataType=[list]
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.

A more complex example that removes semicolon and backslash characters, which cause problems when building a list...

if(Regex([Artist], /#([[:punct:]])#/, 0),
     Contains Punctuation\replace(replace([R1], ;,Semicolon), \, Backslash),
     No Punctuation)\replace(replace([Artist], ;, / and/ ), \, //)&DataType=[list]

Examples using Mode = -1

Regex([Name], /#(\d{1,2})\.(\d{1,2}).(\d{4})#/, -1)[R3]//[R1]//[R2]</nowiki>
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
2009/01/22

... IN PROGRESS ...

(Back to top)