Custom regular expression request

Discussion in 'My TVSeries' started by mfsav2, January 22, 2011.

  1. mfsav2

    mfsav2 Portal Member

    Joined:
    March 11, 2008
    Messages:
    22
    Likes Received:
    0
    Ratings:
    +0 / 0
    :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 (Text):
    1. [i]foo CD01.ext[/i]
    2. will report
    3. Movie: foo
    4. Part: 01
    5. Part2:
    6. Title:
    7. Ext: ext
    8.  
    9. [i]foo CD01 CD02.ext[/i]
    10. will report
    11. Movie: foo
    12. Part: 01
    13. Part2:02
    14. Title:
    15. Ext: ext
    16.  
    17. [i]foo CD0102.ext[/i]
    18. will report
    19. Movie: foo
    20. Part: 01
    21. Part2:02
    22. Title:
    23. Ext: ext
    24.  
    25. [i]foo part01.ext[/i]
    26. will report
    27. Movie: foo
    28. Part: 01
    29. Part2:
    30. Title:
    31. Ext: ext
    32.  
    etc...

    Some samples could be:
    Code (Text):
    1. foo CD1.iso
    2. foo CD1CD2.iso
    3. foo CD1 CD2.iso
    4. foo CD1 CD2 CD3.iso
    5. foo - 1.iso
    6. foo - 01.iso
    7. foo - 02.iso
    8. foo (2001) CD1.iso
    9. foo (2001) CD1CD2.iso
    10. foo (2001) CD1 CD2.iso
    11. foo (2001) CD1 CD2 CD3.iso
    12. foo (2001) part1.iso
    13. foo (2001) - 1.iso
    14. foo (2001) - 01.iso
    15. foo (2001) - 02.iso
    16. foo part1.iso
    17. foo part1part2.iso
    18. foo part1 part2.iso
    19. foo part1 part2 part3.iso
    20. foo (2001) part1.iso
    21. foo (2001) part1part2.iso
    22. foo (2001) part1 part2.iso
    23. foo (2001) part1 part2 part3.iso
    24.  
    I was able to do (starting from yours):
    Code (Text):
    1. ^(?:.*\\)?(?<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?
     
  2. Google AdSense Guest Advertisement



    to hide all adverts.
  3. mfsav2

    mfsav2 Portal Member

    Joined:
    March 11, 2008
    Messages:
    22
    Likes Received:
    0
    Ratings:
    +0 / 0
    Re: Expressions/Rules exchange

    Update

    Code (Text):
    1.  
    2. ^(?:.*\\)?(?<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>[^.]*)$
    3.  
    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
     
  4. Chubler

    Chubler Portal Member

    Joined:
    July 14, 2009
    Messages:
    43
    Likes Received:
    12
    Gender:
    Male
    Ratings:
    +13 / 0
    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).
     
    • Like Like x 1
  5. mfsav2

    mfsav2 Portal Member

    Joined:
    March 11, 2008
    Messages:
    22
    Likes Received:
    0
    Ratings:
    +0 / 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
     
  6. mfsav2

    mfsav2 Portal Member

    Joined:
    March 11, 2008
    Messages:
    22
    Likes Received:
    0
    Ratings:
    +0 / 0
    Re: Expressions/Rules exchange

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

    Mf
     
  7. Chubler

    Chubler Portal Member

    Joined:
    July 14, 2009
    Messages:
    43
    Likes Received:
    12
    Gender:
    Male
    Ratings:
    +13 / 0
    Home Country:
    Australia Australia
    Re: Expressions/Rules exchange

    Strange, I tested it in both Expresso and with Regular Expression Tester and it works fine. Are you using this with the My TVSeries plugin or some other program?
     
  8. mfsav2

    mfsav2 Portal Member

    Joined:
    March 11, 2008
    Messages:
    22
    Likes Received:
    0
    Ratings:
    +0 / 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
     
  9. Chubler

    Chubler Portal Member

    Joined:
    July 14, 2009
    Messages:
    43
    Likes Received:
    12
    Gender:
    Male
    Ratings:
    +13 / 0
    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]
     
  10. mfsav2

    mfsav2 Portal Member

    Joined:
    March 11, 2008
    Messages:
    22
    Likes Received:
    0
    Ratings:
    +0 / 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.
     
  11. RoChess
    • Premium Supporter

    RoChess Extension Developer

    Joined:
    March 10, 2006
    Messages:
    4,182
    Likes Received:
    1,304
    Ratings:
    +1,683 / 2
    Re: Expressions/Rules exchange

    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.
     
Loading...

Users Viewing Thread (Users: 0, Guests: 0)

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice
  • About The Project

    The vision of the MediaPortal project is to create a free open source media centre application, which supports all advanced media centre functions, and is accessible to all Windows users.

    In reaching this goal we are working every day to make sure our software is one of the best.

             

  • Support MediaPortal!

    The team works very hard to make sure the community is running the best HTPC-software. We give away MediaPortal for free but hosting and software is not for us.

    Care to support our work with a few bucks? We'd really appreciate it!