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
Retired Developer
Posts: 12,386
Joined: Nov 2003
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 *.
find quote
jmarshall Offline
Team-XBMC Developer
Posts: 25,669
Joined: Oct 2003
Reputation: 169
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: 524
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: 662
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
Retired Developer
Posts: 12,386
Joined: Nov 2003
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.
find quote
jmarshall Offline
Team-XBMC Developer
Posts: 25,669
Joined: Oct 2003
Reputation: 169
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
J_K_M_A_N Offline
Fan
Posts: 443
Joined: Feb 2006
Reputation: 1
Location: Minnesota
Post: #11
Here is an example: (I know it is not a good way to name my files but it is because I watch them on the computer also and it just looks neater. I am a neat freak. What can I say?)

Studio 60 On The Sunset Strip\Season 1\Studio 60 On The Sunset Strip - Season 1 - Episode 04 - The West Coast Delay.avi

I think one of the problems is the Season 1 directory. I have tried the following expressions:

<regexp>[\._ \-][Season ]([0-9])[\-]?[Episode ]([0-9]*)[^\\/]*</regexp>
<regexp>[\._ \-] Season ([0-9]*)[\-] Episode ([0-9][0-9])[\._ \-][^\\/]*</regexp>
<regexp>[\-]Season ([0-9]+) - Episode ([0-9]+)[^\\/]*</regexp>
<regexp>[\._ \-]*Season([0-9]+)*Episode([0-9]+)*[^\\/]*</regexp>
<regexp>[\\/][\-][Season]([0-9]+)[\-][Episode]([0-9][0-9])[^\\/]*</regexp>

Plus a few others that I overwrote. And I tried yours jmarshall. That didn't work either. Again, I think it is the Season 1 directory before the files but I am not sure.

J_K_M_A_N (You get used to typing that. Smile )
find quote
jmarshall Offline
Team-XBMC Developer
Posts: 25,669
Joined: Oct 2003
Reputation: 169
Post: #12
Season ([0-9]+) - Episode ([0-9]+)

will catch that file. No need to make it more complicated than that.

I used http://www.regextester.com to confirm.

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: #13
I am losing my mind! Now my xbox won't boot if I have an advancedsettings.xml file on it with the <tvshowmatching> entries in it. This is the EXACT contents on my advancedsettings.xml file:

<AdvancedSettings>
<displayremotecodes>true</displayremotecodes>
<tvshowmatching>
<regexp>Season ([0-9]+) - Episode ([0-9]+)</regexp>
</tvshowmatching>
</AdvancedSettings>

If I ONLY have displayremotecodes in it it works fine. When I add <tvshowmatching>, it hangs.

I don't have a debug log because it doesn't make it that far. This is all I get:

18:40:51 M: 52211712 NOTICE: -----------------------------------------------------------------------
18:40:51 M: 52191232 NOTICE: Starting XBoxMediaCenter. Built on Mar 18 2007
18:40:51 M: 52191232 NOTICE: Q is mapped to: Harddisk0\Partition1\XBMC
18:40:51 M: 52191232 NOTICE: Log File is located: Q:\xbmc.log
18:40:51 M: 52191232 NOTICE: -----------------------------------------------------------------------
18:40:51 M: 52191232 NOTICE: Setup DirectX
18:40:52 M: 52146176 NOTICE: load settings...
18:40:52 M: 52146176 NOTICE: loading T:\guisettings.xml
18:40:52 M: 52019200 NOTICE: Getting hardware information now...
18:40:52 M: 52019200 NOTICE: Checking resolution 10
18:40:52 M: 52019200 NOTICE: Setting autoresolution mode 4

I have to quit for now. I am going crazy. Sorry to have wasted all your time. If I get it working I will DEFINITELY update the wiki. Thanks so much for the help.

J_K_M_A_N
find quote
jmarshall Offline
Team-XBMC Developer
Posts: 25,669
Joined: Oct 2003
Reputation: 169
Post: #14
You must have the <twopart> tag present due to a bug (that has been fixed).

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: #15
THANK YOU!

I will try again.

J_K_M_A_N
find quote
Post Reply