Need Regex Help

Come up with a useful post-processing script? Share it here!
Post Reply
randyharris
Full Member
Full Member
Posts: 146
Joined: January 21st, 2010, 5:36 pm

Need Regex Help

Post by randyharris »

The script below in the code box is from a locked thread so I had to start a new one.

Instead of how the example is done below, I would like to get a regex= line for shows the this format:

TV Show - SxxExx.ext

e.g.: Lost - S06E11.m4v

Thanks for your help.

Code: Select all

# regex to match job name to strip out show name, season number, episode number and episode name
# in multi part episodes (eg: Show - 1x01-1x02 - Episode), the first episode (1 in this case) is used
regex="^(.*) - ([[:digit:]])+x([[:digit:]]+).* - (.*)$"


Camelot
Jr. Member
Jr. Member
Posts: 64
Joined: August 18th, 2008, 6:23 am

Re: Need Regex Help

Post by Camelot »

untested:

Code: Select all

regex="^(.+) - S([[:digit:]]+)E([[:digit:]]+).*$"
This will accept something of the format:
"Show name - SxxExx"
which should do the job for you. It will place the showname in placeholder 1, season number in 2 and episode number in 3.

hope that helps
Last edited by Camelot on March 30th, 2010, 3:28 am, edited 1 time in total.
randyharris
Full Member
Full Member
Posts: 146
Joined: January 21st, 2010, 5:36 pm

Re: Need Regex Help

Post by randyharris »

Thanks I'll give this a test.
Camelot wrote: untested:

Code: Select all

regex="^(.+) - S([[:digit:]]+)E([[:digit:]]+).*$"
This will accept something of the format:
"Show name - SxxExx"
which should do the job for you. It will place the showname in placeholder 1, season number in 2 and episode number in 3.

hope that helps
doubledrat
Release Testers
Release Testers
Posts: 180
Joined: February 20th, 2008, 3:16 pm

Re: Need Regex Help

Post by doubledrat »

you might want to make it case insensitive with

Code: Select all

regex="^(.+) - [Ss]([[:digit:]]+)[Ee]([[:digit:]]+).*$"
randyharris
Full Member
Full Member
Posts: 146
Joined: January 21st, 2010, 5:36 pm

Re: Need Regex Help

Post by randyharris »

doubledrat wrote: you might want to make it case insensitive with

Code: Select all

regex="^(.+) - [Ss]([[:digit:]]+)[Ee]([[:digit:]]+).*$"
Thanks doubledrat,

working on the same script - wonder if you could help with this one too...

(case insensitive would be best)

Here is the file name format:

"Formula1.2010.Australian.Grand.Prix.WS.PDTV.XviD-433.avi"

Where it is always going to be SERIES.YEAR.VENUE.garbage

More verbose - the start of the name to but not including the first period is the "Series", the 4 digits between the first and second period is the "YEAR", and between the second and third period is the "Venue"

Also need to figure out how put the three of those together to create the Episode name so that the name would be:
Formula1 2010 - Australia


Thanks if you or anybody can help.
randyharris
Full Member
Full Member
Posts: 146
Joined: January 21st, 2010, 5:36 pm

Re: Need Regex Help

Post by randyharris »

I took a stab at the regex command but it isn't working...

regex="^([a-zA-Z]+*)\.(20[0-9][0-9])\.([a-zA-Z]+)\..*$"
doubledrat
Release Testers
Release Testers
Posts: 180
Joined: February 20th, 2008, 3:16 pm

Re: Need Regex Help

Post by doubledrat »

well, you can do what you've asked to do with

Code: Select all

^([\d\w]+)\.(20[0-9][0-9])\.(.*)$
which will match digits or letters, then a . then a year, then everything else

but what if you have something like

only.the.lonely.2009.blah.blah.blah.avi

I think you need to drop looking for the .

Code: Select all

^(.+)(20[0-9][0-9])(.+)\....$
this will give you

Formula1.
2010
.Australian.Grand.Prix.WS.PDTV.XviD-433

so you'd need to tidy up a bit
Last edited by doubledrat on April 2nd, 2010, 5:15 am, edited 1 time in total.
doubledrat
Release Testers
Release Testers
Posts: 180
Joined: February 20th, 2008, 3:16 pm

Re: Need Regex Help

Post by doubledrat »

this might be better

Code: Select all

^(.+)(20[0-9][0-9])(.+?)([A-Z]{2,})(.*)\....$
will give

Formula1.
2010
.Australian.Grand.Prix.
WS
.PDTV.XviD-433

^ start of string
(.+) any char at least once
(20[0-9][0-9]) a year
(.+?) any char at least once (lazy)
([A-Z]{2,}) any uppercased word with at least 2 letters
(.*) anything else
\. a dot
...$ any 3 chars then the end of the string

you'll then need to remove dots from your strings and trim any leading/trailing spaces, but that should be good to go.
randyharris
Full Member
Full Member
Posts: 146
Joined: January 21st, 2010, 5:36 pm

Re: Need Regex Help

Post by randyharris »

:)
Post Reply