Python Forum
Regex: finding if three groups have a value in them
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Regex: finding if three groups have a value in them
#1
Hello, I have started learning python via documentation & videos because I trying to make a program that converts episode number and timestamps in a .txt to an XML chapter file.

Write now I am trying to take the raw episode raw format and output 1 or 2 numbers and groups 6 is giving me There was no Match when it should be saying 6 is a match. I don't know if I`m going about this the right way, so any Ideas or suggestions would be great.
import re
Input = 'd7 23'
###Input should output 23 via groups 2 or 3 or 6 

##Input = '23'
##Input = 'ep23'
ep_regex = '((?i)EP(\d\d?))?(^\d\d?$)?(((?i)d\w[\s|:])?(\d\d?))?'
ep_prog = re.compile(ep_regex) 
ep_result = ep_prog.match(Input)

one = ep_result.group(1)
two = ep_result.group(2)
three = ep_result.group(3)
four = ep_result.group(4)
five = ep_result.group(5)
six = ep_result.group(6)

if two or three or six is True:
    if two == None:
        print('No match in G2')
        pass
    else:
        print('2 is a Match!')
    if three == None:
        print('no match in G3')
        pass
    else:
        print('3 is a Match!')
    if six == None:
        print('No Match in G6')
        pass
    else:
        print ("6 is a match!")        
else:
    print("There was no Match")
print('group 1 -->',one)
print('group 2 -->',two)
print('group 3 -->',three)
print('group 4 -->',four)
print('group 5 -->',five)
print('group 6 -->',six)
Here`s the error that I WAS getting if that helps.
Error:
Warning(from warnings module): File "C:\Users\new user\Desktop\py read & replace\Regex_Examples\ep_re_group_match.py", line 9 ep_prog = re.compile(ep_regex) DeprecationWarning: Flags not at the start of the expression '((?i)EP(\\d\\d?))?(^\\d' (truncated)
Reply


Messages In This Thread
Regex: finding if three groups have a value in them - by Daring_T - Mar-28-2020, 06:01 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to group related products in relationship groups? RegionHUser 2 252 Jun-02-2024, 03:51 PM
Last Post: Pedroski55
  Ldap Search for finding user Groups ilknurg 1 1,842 Mar-11-2022, 12:10 PM
Last Post: DeaD_EyE
  Regex not finding all unicode characters tantony 3 2,349 Jul-13-2021, 09:11 PM
Last Post: tantony
  Make Groups with the List Elements quest 2 2,049 Jul-11-2021, 09:58 AM
Last Post: perfringo
  Understanding Regex Groups matt_the_hall 5 2,926 Jan-11-2021, 02:55 PM
Last Post: matt_the_hall
  How to solve equations, with groups of variables and or constraints? ThemePark 0 1,739 Oct-05-2020, 07:22 PM
Last Post: ThemePark
  Create homogeneous groups with Kmeans ? preliator 0 1,591 Sep-01-2020, 02:29 PM
Last Post: preliator
  How to take group of numbers summed in groups of 3... jaguare22 1 1,571 May-05-2020, 05:23 AM
Last Post: Yoriz
  Listing groups tharpa 2 2,649 Nov-26-2019, 07:25 AM
Last Post: DeaD_EyE
  groups attribute of a groupby object question smw10c 2 4,389 Apr-27-2017, 03:18 PM
Last Post: smw10c

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020