Custom regular expression request (1 Viewer)

mfsav2

Portal Member
March 11, 2008
22
0
Current version:


Fixes:

:eek: thank you is perfect! :)

I-m not very good in RegEx may I ask your help?

I need to do the same but on multipart movies, like CD1, CD2 and I would like to have an outcome like the one for series:
Your amazing ReGeX n this case:
foo s01e01 - title 1.ext
will report
Series: foo
Season: 01
Episode: 01
Episode2:
Title: title 1
Ext: ext

So can you help me build the RegEx for this case:
Code:
[i]foo CD01.ext[/i]
will report
Movie: foo
Part: 01
Part2:
Title: 
Ext: ext

[i]foo CD01 CD02.ext[/i]
will report
Movie: foo
Part: 01
Part2:02
Title: 
Ext: ext

[i]foo CD0102.ext[/i]
will report
Movie: foo
Part: 01
Part2:02
Title: 
Ext: ext

[i]foo part01.ext[/i]
will report
Movie: foo
Part: 01
Part2:
Title: 
Ext: ext
etc...

Some samples could be:
Code:
foo CD1.iso
foo CD1CD2.iso
foo CD1 CD2.iso
foo CD1 CD2 CD3.iso
foo - 1.iso
foo - 01.iso
foo - 02.iso
foo (2001) CD1.iso
foo (2001) CD1CD2.iso
foo (2001) CD1 CD2.iso
foo (2001) CD1 CD2 CD3.iso
foo (2001) part1.iso
foo (2001) - 1.iso
foo (2001) - 01.iso
foo (2001) - 02.iso
foo part1.iso
foo part1part2.iso
foo part1 part2.iso
foo part1 part2 part3.iso
foo (2001) part1.iso
foo (2001) part1part2.iso
foo (2001) part1 part2.iso
foo (2001) part1 part2 part3.iso

I was able to do (starting from yours):
Code:
^(?:.*\\)?(?<movie>[^\\]+?)[ _.\-\[]+(?:(?:cd[ _.\-\[\]]*)?(?<part>\d+)|(?:part[ _.\-\[\]]*)?(?<part>\d+)|(?:\#|\-\s)(?<part>\d+))(?:[ _.+-]+(?:(?:cd)?\k<part>[ _.\-\[\]]*(?<part2>\d+)|(?:part)?\k<part>[ _.\-\[\]]*(?<part2>\d+)|(?:\#|\-\s)\k<part>(?<part2>\d+))|(?:[ _.+-]*cd(?<part2>\d+))|(?:[ _.+-]*part(?<part2>\d+)))*[ _.\-\[\]]*(?<title>(?![^\\].*?(?<!the)[ .(-]sample[ .)-]).*?)\.(?<ext>[^.]*)$

but I get false positives on
•foo.1x01.1x02.*
(gets the 1.)

foo s01e01 - title 1.ext
gets movie:foo s01e01 - title
part:1

and similar

How can I exclude any form 1.<number> 1x<number> and filter correctly?
 

mfsav2

Portal Member
March 11, 2008
22
0
Re: Expressions/Rules exchange

Update

Code:
^(?:.*\\)?(?<movie>[^\\]+?)(?:(?:cd|part|dvd[ _.\-\[\]]*)(?<part>\d+)|(?:\#|\-\s)(?<part>\d+))(?:[ _.+-]+(?:(?:cd|part|dvd)?\k<part>[ _.\-\[\]]*(?<part2>\d+)|(?:\#|\-\s)\k<part>(?<part2>\d+))|(?:[ _.+-]*cd|part|dvd(?<part2>\d+)))*[ _.\-\[\]]*(?<title>(?![^\\].*?(?<!the)[ .(-]sample[ .)-]).*?)\.(?<ext>[^.]*)$

to avoid false positive on
foo 2.avi

where foo 2 is the title.

In this way the
foo cd.1.avi

is not in the list anymore
 

Chubler

Portal Member
July 14, 2009
46
25
Home Country
Australia Australia
Re: Expressions/Rules exchange

Your probably better off building up an expression that matches what you're after rather that removing unneeded stuff from a quite complex expression. Here is something that matches all your examples and I think you'll find it easier to build on this for new requirements.

[noparse](?<movie>.*?)(?:[- ])+(?:CD|part|DVD)?(?<part1>0*1)? *(?:CD|part|DVD)?(?<part2>0*2)? *(?:CD|part|DVD)?(?:0*3)?\.(?<ext>[^.]*)$[/noparse]

Note: your examples have part3/CD3 but you don't seem to capture it, I've captured it to an unnamed group but you could update to capture it to part3 if you wanted.


BTW I don't think this is the correct thread for this sort of query and it's all probably going to be deleted (perhaps you should have started a new thread).
 

mfsav2

Portal Member
March 11, 2008
22
0
Re: Expressions/Rules exchange

I replied in this thread as I was starting from the latest version of the RegEx.

Thanks a lot for your help, as I said I'm not really good at RegEx so I did non know where to start from
 

mfsav2

Portal Member
March 11, 2008
22
0
Re: Expressions/Rules exchange

Your probably better off building up an expression that matches what you're after rather that removing unneeded stuff from a quite complex expression. Here is something that matches all your examples and I think you'll find it easier to build on this for new requirements.

[noparse](?<movie>.*?)(?:[- ])+(?:CD|part|DVD)?(?<part1>0*1)? *(?:CD|part|DVD)?(?<part2>0*2)? *(?:CD|part|DVD)?(?:0*3)?\.(?<ext>[^.]*)$[/noparse]

Note: your examples have part3/CD3 but you don't seem to capture it, I've captured it to an unnamed group but you could update to capture it to part3 if you wanted.


BTW I don't think this is the correct thread for this sort of query and it's all probably going to be deleted (perhaps you should have started a new thread).

I get an error: Nasted * operator. :eek:

Mf
 

mfsav2

Portal Member
March 11, 2008
22
0
Re: Expressions/Rules exchange

I'm testing it with Expresso and it compiles if I change it like this:
(?<movie>.*?)(?:[- ])+(?:CD|part|DVD)?(?<part1>0*1)? (?:CD|part|DVD)?(?<part2>0*2)? (?:CD|part|DVD)?(?:0*3)?\.(?<ext>[^.]*)$



but then it does not work anymore nor it works on
foo [CD1].avi

So it should be able to match and extract correctly the title, extension and part1-part 2 (eventually nested):
foo CD1.iso
foo CD1CD2.iso
foo CD1 CD2.iso
foo CD1 CD2 CD3.iso
foo - 1.iso
foo - 01.iso
foo - 02.iso
foo (2001) CD1.iso
foo (2001) CD1CD2.iso
foo (2001) CD1 CD2.iso
foo (2001) CD1 CD2 CD3.iso
foo (2001) part1.iso
foo (2001) - 1.iso
foo (2001) - 01.iso
foo (2001) - 02.iso
foo part1.iso
foo part1part2.iso
foo part1 part2.iso
foo part1 part2 part3.iso
foo (2001) part1.iso
foo (2001) part1part2.iso
foo (2001) part1 part2.iso
foo (2001) part1 part2 part3.iso

It should NOT detect
foo 2.iso

but it should detect
foo 2 - 1.iso
foo 2 - 2.iso
foo 2 - CD1.iso
foo 2 - CD2.iso

etc...

:)

Mf
 

Chubler

Portal Member
July 14, 2009
46
25
Home Country
Australia Australia
How about this?
[noparse]^(?<movie>[^-]*?)(?:[- [])+(?:(?:CD|part|DVD)?(?<part1>0*1)]? *(?:(?:CD|part|DVD)?(?<part2>0*2)]? *)?|(?:(?:CD|part|DVD)?(?<part2>0*2)]? *))(?:CD|part|DVD)?(?:0*3])?\.(?<ext>[^.]*)$[/noparse]
 

mfsav2

Portal Member
March 11, 2008
22
0
Re: Expressions/Rules exchange

Expresso still gives me the error:
Nested quantifier *
so I cannot use it with VB.net :(

I use options Ignore Case, Multiline, Ignore Pattern WS, Compiled

RegexBuddy does compile it but it does not match several strings:
movie 2 - 3.mkv
foo CD.1.iso
foo CD1 CD2 CD3.iso
foo (2001) CD1 CD2 CD3.iso
foo (2001) CD1-CD2-CD3.iso
foo part1 part2 part3.iso
foo (2001) part1 part2 part3.iso


If I try the website you suggested I get error :eek::
There was a problem handling your request. The site administrators have been notified, but if the problem persists, please contact us.
 

RoChess

Extension Developer
  • Premium Supporter
  • March 10, 2006
    4,434
    1,897
    Re: Expressions/Rules exchange

    Expresso still gives me the error: Nested quantifier *

    I just copied and pasted his expression in Expresso and it works fine for me. So you might want to look at your method of copy-n-pasting.

    On the other hand his expression is still wrong, but I'm sure he can fix that part for ya.
     

    Users who are viewing this thread

    Top Bottom