#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2016
    Posts
    8
    Rep Power
    0

    regx question - help


    i have this descriptions variable

    NAME 2 - EP. 43
    NAME 6 - EP. 12
    NAME - EP. 43

    I need read the two numbers
    my result is

    2 - 43
    6 - 12
    0 - 43 (or - 43 or only 43)

    thanks for help
  2. #2
  3. Lazy Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    16,334
    Rep Power
    9645
    You can't get "0", but if an empty string is acceptable then a simple regex would be
    Code:
    (\d*) - EP\. (\d*)
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2016
    Posts
    8
    Rep Power
    0
    thanks.
    if EP is a separated or not separated?
    EP. 43
    EP.43

    thanks
  6. #4
  7. Lazy Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    16,334
    Rep Power
    9645
    Try modifying the regex yourself. Post what you tried if it doesn't work.
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2016
    Posts
    8
    Rep Power
    0
    Originally Posted by requinix
    Try modifying the regex yourself. Post what you tried if it doesn't work.
    yes.
    i have write this regex
    (\d*)\s-\sEP\.\s(\d*)
    and it works with all possible cases

    NAME 2 - EP. 43
    NAME 6 - EP. 12
    NAME - EP. 43
    NAME - EP.1

    but a have another problem.
    in some cases, I even text before EP.
    for example

    NAME 2 - THIS IS A TEXT EP. 43

    it is also possible to handle this case in a single expression?

    thanks
  10. #6
  11. Lazy Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    16,334
    Rep Power
    9645
    That part in the middle of the regex which is "whitespace, a hyphen, and whitespace" needs to be changed to "whitespace, a hyphen, whitespace, then some amount of stuff until...".

    Like
    Code:
    (\d*)\s-\s.*?EP\.\s(\d*)
    .*? will match the minimum amount of stuff until the "EP." comes along, but that may be too broad for some of your titles...
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2016
    Posts
    8
    Rep Power
    0
    perfect!
    thanks

IMN logo majestic logo threadwatch logo seochat tools logo