Simple Regex

A forum for general discussion of the Python programming language.

Simple Regex

Postby ylafont » Tue Apr 15, 2014 6:29 pm

I have more than one problem, but this is the first.

387 - TMC Xtra.strm
370 - Starz.strm
331 - BTN 2.strm
30 - QVC.strm
391 - Flix West.strm
359 - Encore Black We.strm
340 - Showtime.strm
3 - CSPAN.strm
303 - HBO Signature.strm
310 - HBO Zone.strm
361 - Encore Action W.strm
371 - Starz Edge.strm

as an example, i am trying the match the exact number at the beginning of the line with Regex. So I figured, this should do it. ^(3)\s.+\.strm this should give me 3 - CSPAN.strm, only

If I don't use the carrot, I will get false positives such as

303 - HBO Signature.strm included with 3 - CSPAN.strm

but I get no hits. did i miss something. thanks. and glad to have you guys back.
ylafont
 
Posts: 23
Joined: Tue Apr 01, 2014 10:29 pm

Re: Simple Regex

Postby Somelauw » Tue Apr 15, 2014 8:06 pm

If I understand your problem correctly.
Each line is formatted as number | space | '-' | space | text | '.strm' (as in the examples)
You want to match all titles that start with number "3".

I think you need the following regex:
^3\s+-\s+.*\.strm
Last edited by Somelauw on Tue Apr 15, 2014 9:36 pm, edited 1 time in total.
Join the #python-forum IRC channel on irc.freenode.net!
Somelauw
 
Posts: 73
Joined: Tue Feb 12, 2013 8:30 pm

Re: Simple Regex

Postby ylafont » Tue Apr 15, 2014 8:24 pm

I used the "3" as an example. that number is taken from a field and matched with it corresponding *.strm file. The Parenthesis were used to isolated each search. So (3) should correctly match

3 - CSPAN.strm
303 - HBO Signature.strm

the Caret ^ should match the 3 (or any other number) if it begins the line, as long as the parenthesis are used should eliminate false positives.
^(3)\s.+\.strm -- should only match -- 3 - CSPAN.strm

^(303)\s.+\.strm -- should only match --- 303 - HBO Signature.strm

but, when the ^ is used, no matches are found.
ylafont
 
Posts: 23
Joined: Tue Apr 01, 2014 10:29 pm

Re: Simple Regex

Postby stranac » Tue Apr 15, 2014 9:34 pm

Maybe you should show your code(something we can run to test), and say what exactly you want to match.
Friendship is magic!

R.I.P. Tracy M. You will be missed.
User avatar
stranac
 
Posts: 1209
Joined: Thu Feb 07, 2013 3:42 pm

Re: Simple Regex

Postby Somelauw » Tue Apr 15, 2014 9:40 pm

ylafont wrote:but, when the ^ is used, no matches are found.


Did you use re.MULTILINE?
Join the #python-forum IRC channel on irc.freenode.net!
Somelauw
 
Posts: 73
Joined: Tue Feb 12, 2013 8:30 pm

Re: Simple Regex

Postby ylafont » Tue Apr 15, 2014 10:49 pm

ok, here goes. I have one regex problem and one logic problem (Which i cant figure out for the life of me), This is my first Python script (never seen it before) so by no means i claim this are the best methods. I am open to what ever changes are recommended.

Code: Select all
#!/usr/bin/env python
from __future__ import unicode_literals
import sys,os,re,fnmatch,glob
import subprocess
import xml.etree.ElementTree as ET

XMLFile = 'xmltv.xml'                        #xmlfile to process
# StrmsDir ='/home/xbmc/Media/OnlineTv/HDHomeRun/'   #Directory of Stream files
StrmsDir ='/home/xbmc/Media/OnlineTv/Richard/'   #Directory of Stream files

DisplayNameCount = []                         #List - Channel Display-Name field counter
DisplayNameMin = 0                           #Channel-Name Minimum Count
DisplayNameMax = 0                           #Channel-Name Maximum Count

def ProcessFiles(self, *args):
   global DisplayNameMin
   global DisplayNameMax
   EmptyField = ''                           #Text to Insert in emtpy fields in order to align tab file
   regpattern = '[A-Z][0-9]+(\.[0-9]+)+'         #Channel ID RegEx Pattern


   if DisplayNameMin == DisplayNameMax:
      print ('Detected  both are equal')
      #ChnInsertPos = 2                     #Position of new Channel-Name insert
      #ColumnToMacth = 1   HAS NOT BEEN TESTED   #XML Columm to match when searching for stream files.
      #ChannelDesc = 3    HAS NOT BEEN TESTED   #Channel Description to fill in settins2.xml
   elif DisplayNameMax == 4:
      #print ('Detected  DisplayNameMax = ', DisplayNameMax)
      ChnInsertPos = 3                     #Position of new Channel-Name insert
      ColumnToMacth = 1                     #XML Columm to match when searching for stream files.
      ChannelDesc = 3                         #Channel Description to fill in settins2.xml
   elif DisplayNameMax == 5:
      # print ('Detected DisplayNameMax = ', DisplayNameMax)
      ChnInsertPos = 2                     #Position of new Channel-Name insert
      ColumnToMacth = 1                     #XML Columm to match when searching for stream files.
      ChannelDesc = 3                        #Channel Description to fill in settins2.xml
   else:
      sys.exit("Could not Detect Number of fields")
      
   with open('settings2.xml','wt', encoding='ISO-8859-1') as file1, open('xmltv.tab','wt', encoding='ISO-8859-1') as file2:
      ChannelGuideNo = 0
      file1.write('<settings> \n')
      for Channel in root.iter('channel'):
         pattern = re.search(regpattern, Channel.attrib.get('id'))
         ChannelID = pattern.group()
         Count = -1                                    #XML Counter begins at ZERO, we minus one in order to match.
         ChannelGuideNo += 1
         
         for ChannelInfo in Channel:   
            if ChannelInfo.tag == 'display-name':
               Count += 1                        
               # print (Count,DisplayNameMin)

         if Count == DisplayNameMin:
            NewChannelInfo = ET.Element('display-name')
            NewChannelInfo.text = EmptyField
            Channel.insert(ChnInsertPos, NewChannelInfo)
         
         ChnPattern = Channel[ColumnToMacth].text                     #XML Field used to match Stream files, from (xmltv.xml)
         
         
         # ##### GLOB MATCH
         
         # StrmSearch = glob.glob(StrmsDir + (ChnPattern +'*.strm'))
         # StrmFile = str(StrmSearch)[2:-2]                              # Remove first and Last 2 characters Stream-File
         # NewChannelInfo = ET.Element('display-name')                     # Create a new entry within the XML file.
         # NewChannelInfo.text = StrmFile
         # Channel.insert(DisplayNameMax+1, NewChannelInfo)

         # if StrmFile == "":
            # NewChannelInfo = ET.Element('display-name')
            # NewChannelInfo.text = EmptyField
            # Channel.insert(DisplayNameMax+1, NewChannelInfo)
         # ###### GLOB END
         
         ### FNMATCH
         ###   regex Pattern = ('('+ ChnPattern + ')'.+\.strm)
         
         files = os.listdir(StrmsDir)
         for files in os.listdir(StrmsDir):
            # # if re.match ('(47.3).+\.strm',x):
            test1 = re.match ('(' + ChnPattern + ')\s.+\.strm', files)
            if test1:
               # print (test1.group())
               NewChannelInfo = ET.Element('display-name')
               NewChannelInfo.text = StrmsDir + files
               Channel.insert(DisplayNameMax+1, NewChannelInfo)
            if test1 is None:
               print ('No Match Found')
               NewChannelInfo = ET.Element('display-name')
               NewChannelInfo.text = 'No Match'
               Channel.insert(DisplayNameMax+1, NewChannelInfo)               
         ############  FNMACTH END      
            
            
         #TAB Delimited file Generation.
         # print ('Now creating TAB delimited file for later use if necessary')
         TabFile = ChannelID + '\t' +'\t'.join(ChannelInfo.text for ChannelInfo in Channel) + '\n'
         file2.write (TabFile)

         # if Channel[DisplayNameMax+1].text != "":
            # # PseudoTv Live HD-Homerun Channel generation.
            # # print ('Now creating Setting2.xml for PseudoTV Live')
            # file1.write('\t <setting id="Channel_' + str(ChannelGuideNo) + '_type" value="8" />\n' );
            # file1.write('\t <setting id="Channel_' + str(ChannelGuideNo) + '_time" value="0" />\n' );
            # file1.write('\t <setting id="Channel_' + str(ChannelGuideNo) + '_1" value="' + ChannelID + '.microsoft.com" />\n' );
            # file1.write('\t <setting id="Channel_' + str(ChannelGuideNo) + '_2" value="' + Channel[DisplayNameMax+1].text + '" />\n' );
            # file1.write('\t <setting id="Channel_' + str(ChannelGuideNo) + '_3" value="xmltv" />\n');
            # file1.write('\t <setting id="Channel_' + str(ChannelGuideNo) + '_4" value="' + Channel[ChannelDesc].text + '" />\n' );
            # file1.write('\t <setting id="Channel_' + str(ChannelGuideNo) + '_rulecount" value="1" />\n');
            # file1.write('\t <setting id="Channel_' + str(ChannelGuideNo) + '_rule_1_id" value="1" />\n');
            # file1.write('\t <setting id="Channel_' + str(ChannelGuideNo) + '_rule_1_opt_1" value="' + Channel[0].text + '" />\n' );   
            # file1.write('\t <setting id="Channel_' + str(ChannelGuideNo) + '_changed" value="False" />\n');
            # file1.write('\n');    
         
      file1.write('</settings>');
      file1.close(), file2.close()
   return

def xmlInfo(self, *args):
   global DisplayNameMin
   global DisplayNameMax
   ChannelCount = 0
   LinesProcessed = 0
   Count = 0

   for Channel in root.iter('channel'):
      ChannelCount += 1      
      Count = 0   

      for ChannelInfo in Channel:   
         Count += 1
         if ChannelInfo.tag == 'display-name':
            LinesProcessed += 1
      
      if Count > 1:
         DisplayNameCount.append (Count)
         DisplayNameMin = (min(DisplayNameCount)-1)
         DisplayNameMax = (max(DisplayNameCount)-1)
         
   print (' \t \t  \t \tChannel    Lines')
   print ('\t    Filename   Min-Max \t Count   Processed')
   print ('----------------------------------------------------')
   print ('Processed: ', XMLFile,'\t', DisplayNameMin, DisplayNameMax,'\t ' ,ChannelCount,'\t   ', LinesProcessed)   
   print ()
   print ('Reminder!!  Counter starts at "0  -  ZERO"' )
   print ()
   print ()
   print ('Settings2.xml has been created')
   print ('xmltv.tab has been created for later use if necessary.')
   print ()
   print ()
   return

if os.path.isfile(XMLFile):
   os.system('clear')
   print
   tree = ET.parse(XMLFile)
   root = tree.getroot()
   xmlInfo(XMLFile)
   ProcessFiles(XMLFile)
   
else:
   os.system('clear')
   CreatXML = input("xmltv.xml does NOT EXIST, Create it y/n? ")
   if CreatXML.lower () == 'y':
      if os.path.isfile('mc2xml'):
         zipcode = input("Please Enter your 5 digit zipcode? ")
         cmd = 'sudo ./mc2xml -c us -d 1 -g ' + zipcode
         subprocess.call([cmd], shell=True)
         tree = ET.parse(XMLFile)
         root = tree.getroot()
         xmlInfo(XMLFile)
         ProcessFiles(XMLFile)
   else:
      print ('Before we can continue, the file XMLTV.TV MUST exist please asure that that mc2xml is the same direc')
      sys.exit()      


first the regex,

I a have a folder many files all beginning with a channel number and ending with extension of .strm. e.g.
391 - Flix West.strm
359 - Encore Black We.strm
333 - Golf Channel.strm
340 - Showtime.strm
3 - CSPAN.strm
303 - HBO Signature.strm
310 - HBO Zone.strm
361 - Encore Action W.strm
371 - Starz Edge.strm

There is and xml file with the following format.

<channel id="I12.28457269.microsoft.com">
<display-name>12 LOOR012</display-name>
<display-name>12</display-name>
<display-name>LOOR012</display-name>
<display-name>Local Origination - LOOR012</display-name>
<display-name>Cablecast</display-name>
</channel>

The script, is supposed to match the Channel number of the xml file with corresponding .strm. If a match is found, a new field is created with corresponding match or a blank entry if nothing is found.

I have tried glob. fnmatch, regex to see what works best.

Glob Worked but gave me more than one match.
Code: Select all
         # ##### GLOB MATCH
         
         # StrmSearch = glob.glob(StrmsDir + (ChnPattern +'*.strm'))
         # StrmFile = str(StrmSearch)[2:-2]                              # Remove first and Last 2 characters Stream-File
         # NewChannelInfo = ET.Element('display-name')                     # Create a new entry within the XML file.
         # NewChannelInfo.text = StrmFile
         # Channel.insert(DisplayNameMax+1, NewChannelInfo)

         # if StrmFile == "":
            # NewChannelInfo = ET.Element('display-name')
            # NewChannelInfo.text = EmptyField
            # Channel.insert(DisplayNameMax+1, NewChannelInfo)
         # ###### GLOB END


With re.match - i get a match, but not using the caret. i also tried the regex expresion ^(3)\s+.*\.strm on to see if i got a hit, but no go.
Code: Select all
         ### FNMATCH
         ###   regex Pattern = ('('+ ChnPattern + ')'.+\.strm)
         
         files = os.listdir(StrmsDir)
         for files in os.listdir(StrmsDir):
            # # if re.match ('(47.3).+\.strm',x):
            test1 = re.match ('(' + ChnPattern + ')\s.+\.strm', files)
            if test1:
               # print (test1.group())
               NewChannelInfo = ET.Element('display-name')
               NewChannelInfo.text = StrmsDir + files
               Channel.insert(DisplayNameMax+1, NewChannelInfo)
            [b]if test1 is None:
               print ('No Match Found')
               NewChannelInfo = ET.Element('display-name')
               NewChannelInfo.text = 'No Match'
               Channel.insert(DisplayNameMax+1, NewChannelInfo)      [/b]         
         ############  FNMACTH END      



The Logic problem occurs witht he second if statement of the insert.

Code: Select all
      [b]if test1 is None:
               print ('No Match Found')
               NewChannelInfo = ET.Element('display-name')
               NewChannelInfo.text = 'No Match'
               Channel.insert(DisplayNameMax+1, NewChannelInfo)      [/b]         
         ############  FNMACTH END      


which, just created a column for each None entry. If the second if statement is removed the script works properly but does not create an empty value for non match entries.

I appreciate the assistance, thank you in advance.
ylafont
 
Posts: 23
Joined: Tue Apr 01, 2014 10:29 pm

Re: Simple Regex

Postby ylafont » Thu Apr 17, 2014 12:41 am

I was able to solve my logic problem not using a for loop to cycle through the list of files. Rather, I made the files list a string and performed the RegEx in it.

Code: Select all
FilesList = str(os.listdir(StrmsDir))


When searching for a match i am using the expression

Code: Select all
"('" + ChnPattern + ")\s+-\s+[a-zA-Z0-9\s_\-\(\)\&!\.]*.strm"


However, this fails to find a match for characters that I not specified within the RegEx. if have tried variations of lookahead unsuccessfully like

(1833)(?=(\.strm)) and
(1833)[\s\S]*(?=.strm) and
(1833).*(?=')

Is there a more direct approach to isolating the file name?

Sample Data: Basically, the Channel numnber us match and all text is taken up to and including the file extenstion the ends in .strm.

Code: Select all
['1833 - MC_ Classic Cou.strm', '1823 - MC_ Kidz Only.strm', '896 - EPIX 2 HD.strm', '358 - Encore Black.strm', '219 - WMPTDT (WMPT-DT).strm', '164 - IFC.strm', '1548 - Dominican View.strm', '29 - WUSA.strm', '211 - WRCDT (WRC-DT).strm', '715 - Big Ten Network.strm', '1479 - MLB _ NHL 05.strm', '1773 - Channel 1 Russi.strm', '1808 - MC_ R&B Classic.strm', '847 - Starz! Comedy H.strm', '632 - Nat Geo Wild HD.strm', '860 - NFL Network HD.strm', '457 - MHZ 7 VC.strm', '1015 - WHAGDT (WHAG-DT).strm', '373 - Starz Kids.strm', '1690 - Ultra Cine.strm', '116 - H2.strm', '1493 - NBA _ MLS 04.strm', '721 - Fox College Sports - Central.strm', '641 - De Pelicula US Feed.strm', '1782 - Israeli Network.strm', '1809 - MC_ R&B Soul.strm', '1536 - TyC Sports.strm', '83 - Fox Sports 1.strm', '481 - WMPT V-me.strm', '911 - HBO Zone HD (We.strm', '291 - Eternal Word Television Network.strm', '181 - Discovery Fit and Health.strm', '22 - WMPT.strm', '7 - WZDC-LP.strm', '1803 - MC_ MCU.strm', '1820 - MC_ Pop Hits.strm', '109 - National Geographic Channel.strm', '1570 - Ultra Docu HD.strm', '404 - Music Choice_ MCU.strm', '184 - GSN.strm', '43 - ESPN2.strm', '731 - AMC (HD).strm', '1590 - Latele Novela.strm', '180 - NFL NETWORK.strm', "1831 - MC_ Today's Cou.strm", '100 - TV Guide Network.strm', '54 - Animal Planet.strm', '400 - HBO.strm', '88 - NFL Network.strm', '271 - WNVCDT (WNVC-DT).strm', '928 - MovieMAX HD.strm', '247 - MASN HD.strm', '458 - MHZ CCTV News.strm', '1705 - Nuestra Tele.strm', '1515 - Antena 3 Intern.strm', '405 - Music Choice_ Hip-Hop and R&B.strm', '1540 - CNN Espanol.strm', '151 - Movies On Demand.strm', '21 - Local Origination - LOOR021.strm', '424 - Music Choice_ Kidz Only!.strm', '1815 - MC_ Adult Alter.strm', '573 - ESPNU HD.strm', '246 - NFL Network HD.strm', '554 - Spike HD (East).strm', '1490 - NBA _ MLS 01.strm', '134 - Encore Family.strm', '78 - CSN MidAtlantic.strm', '1821 - MC_ Party Favor.strm', '1563 - Discovery Espan.strm', '1488 - MLB _ NHL 14.strm', '395 - EPIX SD.strm', '220 - WETADT (WETA-DT).strm', '90 - NBC Sports Netw.strm', '507 - WJLA-DTV.strm', '1471 - Game HD 6.strm', '868 - Animal Planet HD.strm', '1799 - MC_ Play.strm', '929 - MAX Latino HD.strm', '217 - Science Channel HD.strm', '125 - Disney Junior US.strm', '789 - Game HD.strm', '451 - MHZ 1 World Vie.strm', '1567 - Canal Once.strm', '1801 - MC_ Pop Rhythmi.strm', '235 - USA Network HD.strm', '1762 - SBS.strm', '341 - SHO 2.strm', '372 - Starz in Black.strm', '366 - Movies On Demand.strm', '1453 - TEAM HD 4 (NBA_.strm', '232 - TBS HD.strm', '73 - VH1.strm', '1819 - MC_ Love Songs.strm', '385 - TMC.strm', '921 - Cinemax HD West.strm', '591 - Outdoor Channel.strm', '887 - UP HD.strm', '1662 - Telehit.strm', '124 - Pentagon Channe.strm', '1692 - Ultra MEX.strm', '72 - MTV - Music Television.strm', '1507 - Super Canal.strm', '923 - More MAX HD (We.strm', '368 - Showtime Showca.strm', '223 - A&E Network HD East.strm', '1805 - MC_ Rap.strm', '1521 - Fox Deportes (S.strm', '239 - The Discovery Channel HD.strm', '1481 - MLB _ NHL 07.strm', '569 - AXS.tv.strm', '1785 - Rang A Rang (Fa.strm', '121 - Do-It-Yourself Network.strm', '40 - Fox News Channel.strm', '1832 - MC_ Country Hit.strm', '685 - Bravo HD.strm', '644 - Oxygen HD (East.strm', '123 - Oxygen.strm', '1806 - MC_ Hip-Hop Cla.strm', '287 - Daystar Television Network.strm', '108 - National Geographic Wild.strm', '369 - Starz HD.strm', '6 - Local Origination - LOOR006.strm', '1516 - Multimedios HD.strm', '51 - History.strm', '455 - MHZ 5 RTTV.strm', '1538 - BeIN Sport en E.strm', '522 - WMPT-DTV.strm', '70 - Spike TV.strm', '899 - Investigation Discovery HD.strm', '126 - Military Histor.strm', '550 - Local Origination - LOOR550.strm', '912 - HBO Latino HD.strm', '274 - WNVCDT4 (WNVC-DT4).strm', '290 - Trinity Broadcasting Network.strm', '85 - BTN.strm', '425 - Music Choice_ Toddler Tunes.strm', '895 - Lifetime Movie Network HD.strm', '589 - NBA TV HD.strm', '17 - WPXW.strm', '119 - Lifetime Movie Network.strm', '1663 - Bandamax Estado.strm', '508 - News 8 HD (MD).strm', '867 - Showcase HD.strm', '690 - ABP NEWS US.strm', '1783 - Pro TV (RSC-3).strm', '1756 - GMA Pinoy.strm', '412 - Music Choice_ Reggae.strm', '402 - Music Choice_ Pop Rhythmic.strm', '117 - WE tv.strm', '752 - NBA League Pass 2.strm', '216 - FUSE.strm', '453 - MHZ 3 France.strm', '1754 - SET Asia.strm', '904 - HBO Signature H.strm', '1670 - Ultra Fiesta.strm', '906 - HBO Family HD.strm', '1776 - TVP Polonia.strm', '1703 - CentroAmerica T.strm', '567 - Galavision Cable Network.strm', '1486 - MLB _ NHL 12.strm', '905 - HBO Signature H.strm', '350 - The Movie Channel.strm', '1802 - MC_ Dance_EDM.strm', '668 - WKTV1.strm', '633 - Telehit USA feed.strm', '8 - Comcast Network (Mid-Atlantic).strm', '710 - MTV HD (East).strm', '1583 - Pasiones.strm', '307 - Outdoor Channel.strm', '5 - Home Shopping Network.strm', '757 - NBA League Pass 7.strm', '275 - WNVCDT5 (WNVC-DT5).strm', '166 - FearNet On Demand.strm', '1836 - MC_ Musica Urba.strm', '558 - WMDOLD2 (WMDO-LD2).strm', '26 - WETADT4 (WETA-DT4).strm', '492 - ION Life.strm', '196 - E! TV East.strm', '780 - GAME 10.strm', '622 - Ecuavisa International.strm',

Thank you for assistance.
ylafont
 
Posts: 23
Joined: Tue Apr 01, 2014 10:29 pm

Re: Simple Regex

Postby ylafont » Thu Apr 17, 2014 3:17 am

For those interested in the solution:


(?<=')896\s-\s.*?(?=')


(?<=') = Called positive Look-Behind and searches for is after the equal sign. in this case it is an apostrophe (')

896 = channel number being search

\s-\s.* - any space - dash -space sequence.

? = greedy character - not sure why it is needed but it is.

(?=') = positive look-forward. - searches for what ever is after the equal sign. in this case it is an apostrophe (')
ylafont
 
Posts: 23
Joined: Tue Apr 01, 2014 10:29 pm

Re: Simple Regex

Postby stranac » Thu Apr 17, 2014 9:33 am

That's a horrible solution.

If you want to find a file that starts with '896', followed by some spaces, you can just use:
Code: Select all
>>> files = ['1833 - MC_ Classic Cou.strm', '1823 - MC_ Kidz Only.strm', ..., '622 - Ecuavisa International.strm', ]
>>> first_match = next(f for f in files if f.split()[0] == '896')
>>> first_match
'896 - EPIX 2 HD.strm'

But you still haven't actually explained what you want to match, so I can't be sure that's what you want...
Friendship is magic!

R.I.P. Tracy M. You will be missed.
User avatar
stranac
 
Posts: 1209
Joined: Thu Feb 07, 2013 3:42 pm

Re: Simple Regex

Postby ylafont » Thu Apr 17, 2014 5:30 pm

It was an attempt while i was waiting on guidance, as I mentioned previously, i am not a programmer. I know it was not pretty, but it does work. I will continue to improve upon it base on your recommendations. I thought I mentioned the matching pattern, From the sample list string, find the specific corresponding .strm file matching the channel number. I like your solution although I have to time to completely understand it, it doesn't even use RegEx.

A couple of things. Since i am creating fields in and XML i had remove the for loop, not sure it i will run into the same problem.

what happens if the first channel found is 1896? wouldn't that be reported as a match?
ylafont
 
Posts: 23
Joined: Tue Apr 01, 2014 10:29 pm

Re: Simple Regex

Postby stranac » Thu Apr 17, 2014 5:42 pm

ylafont wrote:Since i am creating fields in and XML i had remove the for loop, not sure it i will run into the same problem.

Sorry, can't quite tell what that sentence means,
ylafont wrote:what happens if the first channel found is 1896? wouldn't that be reported as a match?

No... Do you know how split works?
Friendship is magic!

R.I.P. Tracy M. You will be missed.
User avatar
stranac
 
Posts: 1209
Joined: Thu Feb 07, 2013 3:42 pm

Re: Simple Regex

Postby ylafont » Thu Apr 17, 2014 6:04 pm

ylafont wrote:what happens if the first channel found is 1896? wouldn't that be reported as a match?

No... Do you know how split works?[/quote]

I didn't know what python was up until a week ago, I am sure i can figure it out. my problem is finding the best solution for the task at hand and how to best apply it. i went from glob, to fnmatch to re.match

believed re.match was the appropriate tool. thanks for the info, I will study your solution and implement it.
ylafont
 
Posts: 23
Joined: Tue Apr 01, 2014 10:29 pm


Return to General Discussions

Who is online

Users browsing this forum: No registered users and 3 guests