Regular Expressions

  Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Post Reply
blakholephysics Offline
Member
Posts: 67
Joined: Jun 2006
Reputation: 0
Post: #1
It seems like I'm missing something but I'm having trouble with the regular expressions. I don't understand how to modify them.

Could someone explain some of this to me?

Code:
<tvshowmatching>
    <regexp>\[[Ss]([0-9]*)\]_\[[Ee]([0-9]*)[^\\/]*</regexp>
    <regexp>[\._ \-]([0-9]*)x([0-9]*)[^\\/]*</regexp>
    <regexp>[\._ \-][Ss]([0-9]*)[\.\-]?[Ee]([0-9]*)[^\\/]*</regexp>
    <regexp>[\._ \-]([0-9]*)([0-9][0-9])[\._ \-][^\\/]*</regexp>
    <twopart>
        <regexp>\[[Ss]([0-9]*)\]_\[[Ee][0-9][0-9]\-([0-9]*)\][^\\/]*</regexp>
        <regexp>[\._ \-][Ss]([0-9]*)[^0-9]*[Ee][0-9][0-9]\-([0-9]*)[^\\/]*</regexp>
        <regexp>[\._ \-][0-9]*x[0-9]*[\._ \-]*([0-9]*)x([0-9]*)[^\\/]*</regexp>
    </twopart>
  </tvshowmatching>

Specifically, I format my tv shows with /tvshowname/season#/episode# - episodetitle.extension

And I'm not sure how to modify this part of the advanced settings to do that.
find quote
spiff Offline
Grumpy Bastard Developer
Posts: 12,174
Joined: Nov 2003
Reputation: 81
Post: #2
first, there was a bug in svn that i fixed @ rev 8255.

second;

a regexp for your scheme would be:

season([0-9]+)[\\/]episode([0-9]+)[^\\/]*

now, the explanation (man, i'm patient today):

the season part should be explanatory; we need it to say 'season' at the start of of pattern. then we need 1 or more numbers. we state that we only allow numbers by the [0-9] part. this defines a list of allowed characters - 0-9 is expanded into 0 1 2 3 4 5 6 7 8 9. we say that we need one of more this using the + sign. now, since this is the season number and that's what we are after, we select this part. this is done by embracing it in parantheses - ([0-9]+). now we need either a backslash or a slash. since a backslash has a special meaning in regular expressions we tell the parser that we mean a litteral \ by doing \\. then it needs episode literally, and we do the same thing to select the episode number. finally we want to make sure we match at the end of the path and not in the middle of it. we do that by specifying a list of not allowed characters, namely \ and /. this we do by putting a ^ inside the []'s, inverting the meaning of the list. finally we need 0 or more of these non-slash characters, which we indicate by a *.

Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.
find quote
jmarshall Offline
Team-XBMC Developer
Posts: 24,520
Joined: Oct 2003
Reputation: 138
Post: #3
Send that man a beer (hell - a whole crate for that effort Smile

Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.


[Image: badge.gif]
find quote
J_K_M_A_N Offline
Fan
Posts: 443
Joined: Feb 2006
Reputation: 1
Location: Minnesota
Post: #4
Wow spiff. That was VERY helpful. Thank you for being patient today. I may actually be able to work mine out now.

If I figure that out, maybe I can figure out how to change the wiki. I will do my best to make you proud.

J_K_M_A_N
find quote
blakholephysics Offline
Member
Posts: 67
Joined: Jun 2006
Reputation: 0
Post: #5
That explanation is great. (we really do need something like that in the wiki)

I'm trying to read these expressions and looking at the first expression listed in the wiki:
Code:
\[[Ss]([0-9]*)\]_\[[Ee]([0-9]*)[^\\/]*

Why a backslash in the beginning? (does it indicate a literal "[" and then later a literal "]"?)
Why the underscore?
Why Ss and Ee? I thought that they were case insensitive.

Code:
[\._ \-]([0-9]*)x([0-9]*)[^\\/]*

Why two backslashes in the first segment? [\._ \-]

Now with what I am trying to do: season #\# - Episodetitle.extension

would This be the correct expression?
Code:
season ([0-9]+)[\\/]([0-9]+) - [^\\/]
find quote
DonJ Offline
Team-XBMC Member
Posts: 490
Joined: May 2005
Reputation: 5
Post: #6
\[ means a literal [
[Ss] means a capital S or a small s.
\] means a literal ]
_ means underscore
[Ee] means E or e

regular expressions are not case insensitive

[\._ \-] means literal . or underscore or literal -

Your regular expression looks ok to me.
find quote
J_K_M_A_N Offline
Fan
Posts: 443
Joined: Feb 2006
Reputation: 1
Location: Minnesota
Post: #7
Man I feel like a complete MORON! I have my files like so:

Series Name\Season #\Series Name - Season # - Episode ## - Episode Name.avi

I thought the expression I would want would be:

[\\/][\-][Season]([0-9]+)[\-][Episode]([0-9][0-9])[^\\/]*

But that doesn't work. I am taking the season number from the file name. Should I take it from the directory instead? Can anyone give me a clue?

J_K_M_A_N

(sorry spiff Sad )
find quote
szsori Offline
TheTVDB.com Admin
Posts: 663
Joined: Aug 2006
Reputation: 1
Location: Milwaukee, WI
Post: #8
J_K_M_A_N Wrote:Series Name\Season #\Series Name - Season # - Episode ## - Episode Name.avi

I thought the expression I would want would be:

[\\/][\-][Season]([0-9]+)[\-][Episode]([0-9][0-9])[^\\/]*

But that doesn't work. I am taking the season number from the file name. Should I take it from the directory instead? Can anyone give me a clue?
Can you give an example filename and path? It's hard to tell which of the following you have:

Lost\1\Lost - 1 - 01 - Pilot.avi
Lost\Season 1\Lost - Season 1 - Episode 01 - Pilot.avi

With an example we can be sure we give you exactly what you need.
find quote
spiff Offline
Grumpy Bastard Developer
Posts: 12,174
Joined: Nov 2003
Reputation: 81
Post: #9
you're missing the spaces...
plus you're saying that your pattern should start with a \ or a /, inconsistent with the seriesname part of your example.

Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.
find quote
jmarshall Offline
Team-XBMC Developer
Posts: 24,520
Joined: Oct 2003
Reputation: 138
Post: #10
J_K_M_A_N (man that's hard to type Tongue)

You are wanting to match:

\Series Name - Season # - Episode ## - Episode Name.avi

Assuming your spacing includes those spaces, you need the "Season " then you need the number, then " - Episode " then the number:

Season ([0-9]+) - Episode ([0-9]+)[^\\/]*

You don't care what's after the Episode number, except that you don't want a slash as it has to be in the filename.

I'm sure you can mod it to include/not include spaces as necessary.

And please: Add to the wiki with your example regexp, the names it matches, and your explanation on how it works.

Cheers,
Jonathan

Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.


[Image: badge.gif]
find quote
Post Reply