andy vt's tools & blog

Flexibility isn't free

About this Page

  • Title:
  • Moderated By:
  • Created:
  • Modified:
  • Modified By: babgvant
  • Revision:

  • Internal Url:

Common Tasks

Regular Expressions

This section is a repository for useful regular expressions. 

ChangeContextValue Action

The following regular expression should allow full access to the path, filename, and extension when using the ChangeContextValue Action.  I’m sure there is a more efficient way to do it, but this works just fine.

FindRegex: ^((.*\\)(.*)\.(.*))\z

ReplaceRegex:

  • $1 = E:\Recorded TV\subdir\another one\Dirty Sexy Money_WJLA-DT_10_10_2007_22_00_01.dvr-ms
  • $2 = E:\Recorded TV\subdir\another one\
  • $3 = Dirty Sexy Money_WJLA-DT_10_10_2007_22_00_01
  • $4 = dvr-ms

So, if you want to change the extension, the ReplaceRegex value would be:

$2$3.wmv

If you want to change the path, the ReplaceRegex would be:

C:\New Path\$3.$4

I don’t suggest using this to change the filename (use the AdvancedFileRename Action instead).  However, if you insist, the ReplaceRegex would be:

$2$3 (FIXED).$4

Windows Media Center File Name

Format: Title_CHAN_09_30_2006_20_28_02.dvr-ms
Regex: ([^\\]+)_([A-Z]+)_(?=0?(\d+))(\d{2})_(?=0?(\d+))(\d{2})_(?=\d{2}(\d{2}))(\d{4})_(?=0?(\d+))(\d{2})_(?=0?(\d+))(\d{2})_(?=0?(\d+))(\d{2})\.(.+)\z
Back References:

Back RefDescriptionValue
$1The title of the showTitle_CHAN_09_30_2006_20_28_02.dvr-ms
$2Channel short nameTitle_CHAN_09_30_2006_20_28_02.dvr-ms
$3Month (m)Title_CHAN_09_30_2006_20_28_02.dvr-ms
$4Month (mm)Title_CHAN_09_30_2006_20_28_02.dvr-ms
$5Day (d)Title_CHAN_09_30_2006_20_28_02.dvr-ms
$6Day (dd)Title_CHAN_09_30_2006_20_28_02.dvr-ms
$7Year (yy)Title_CHAN_09_30_2006_20_28_02.dvr-ms
$8Year (yyyy)Title_CHAN_09_30_2006_20_28_02.dvr-ms
$9Hour (h)Title_CHAN_09_30_2006_20_28_02.dvr-ms
$10Hour (hh)Title_CHAN_09_30_2006_20_28_02.dvr-ms
$11Minutes (m)Title_CHAN_09_30_2006_20_28_02.dvr-ms
$12Minutes (mm)Title_CHAN_09_30_2006_20_28_02.dvr-ms
$13Seconds (s)Title_CHAN_09_30_2006_20_28_02.dvr-ms
$14Seconds (ss)Title_CHAN_09_30_2006_20_28_02.dvr-ms
$15File ExtensionTitle_CHAN_09_30_2006_20_28_02.dvr-ms
$ Title_CHAN_09_30_2006_20_28_02.dvr-ms

%WM/MediaOriginalBroadcastDateTime%

Format: 2005-01-01
Regex: "(?=\d{2}(\d{2}))(\d{4})-(?=0?(\d+))(\d{2})-(?=0?(\d+))(\d{2})"
Back References:

$1: Year (yy)
$2: Year (yyyy)
$3: Month (m)
$4: Month (mm)
$5: Day (d)
$6: Day (dd)

------------------------
%WM/OriginalReleaseTime%

Format: 2004-01-01T00:00:00.0000000-08:00
Regex:  (?=\d{2}(\d{2}))(\d{4})-(?=0?(\d+))(\d{2})-(?=0?(\d+))(\d{2})T(\d{2}):(\d{2}):(\d{2})\.\d+-(\d{2}):(\d{2})
Back References:

$1: Year (yy)
$2: Year (yyyy)
$3: Month (m)
$4: Month (mm)
$5: Day (d)
$6: Day (dd)
$7: Hour (hh)
$8: Minutes (nn)
$9: Seconds (ss)
$10: Milliseconds? (iiiiii)
$11: Time Zone Info (-hh:mm)
$12: Positive or negative time zone difference (-)
$13: Time Zone Hour (hh)
$14: Time Zone Minute (mm)


------------------------
%WM/OriginalReleaseTime%

Format: 2004-01-01T000000.0000000-0800
Regex:  (?=\d{2}(\d{2}))(\d{4})-(?=0?(\d+))(\d{2})-(?=0?(\d+))(\d{2})T(\d{2})(\d{2})(\d{2})\.(\d+)(([+-])(\d{2})(\d{2}))
Back References:

$1: Year (yy)
$2: Year (yyyy)
$3: Month (m)
$4: Month (mm)
$5: Day (d)
$6: Day (dd)
$7: Hour (hh)
$8: Minutes (nn)
$9: Seconds (ss)
$10: Milliseconds? (iiiiii)
$11: Time Zone Info (-hh:mm)
$12: Positive or negative time zone difference (-)
$13: Time Zone Hour (hh)
$14: Time Zone Minute (mm)

@2008 andy vt
Powered by Community Server (Non-Commercial Edition), by Telligent Systems