tickettypepat = (r'MIS Notes:.*(//p//)?.*')
retype = re.search(tickettypepat,line)
if retype:
print retype.group(0)
print retype.group(1)
Given the input.
MIS Notes: //p//
Can anyone tell me why group(0) is
MIS Notes: //p//
and group(1) is returning as None?
I was originally using regex because, before I ran into problems the matching was more complex than just matching //p// here's the full code. I'm fairly new at this so forgive my noobness, I'm sure there are better ways of accomplishing much of this and if anyonee feels like pointing those out that would be awesome. But aside from the problem with the regex for //[pewPEW]// being too greedy it seems to be functional. I appreciate the help.
Takes Text and cleans up / converts some things.
filename = (r'.\4-12_4-26.txt')
import re
import sys
#Clean up output from the web to ensure that you have one catagory per line
f = open(filename)
w = open('cleantext.txt','w')
origdatepat = (r'(Ticket Date: )([0-9]+/[0-9]+/[0-9]+),( [0-9]+:[0-9]+ [PA]M)')
tickettypepat = (r'MIS Notes:.*(//[pewPEW]//)?.*')
print 'Begining Blank Line Removal'
for line in f:
redate = re.search(origdatepat,line)
retype = re.search(tickettypepat,line)
if line == ' \n':
line = ''
print 'Removing blank Line'
#remove ',' from time and date line
elif redate:
line = redate.group(1) + redate.group(2)+ redate.group(3)+'\n'
print 'Redating... ' + line
elif retype:
print retype.group(0)
print retype.group(1)
if retype.group(1) == '//p//':
line = line + 'Type: Phone\n'
print 'Setting type for... ' + line
elif retype.group(1) == '//e//':
line = line + 'Type: Email\n'
print 'Setting type for... ' + line
elif retype.group(1) == '//w//':
line = line + 'Type: Walk-in\n'
print 'Setting type for... ' + line
elif retype.group(1) == ('' or None):
line = line + 'Type: Ticket\n'
print 'Setting type for... ' + line
w.write(line)
print 'Closing Files'
f.close()
w.close()
And here's some sample input.
Ticket No.: 20100426132
Ticket Date: 04/26/10, 10:22 AM
Close Date:
Primary User: XXX
Branch: XXX
Help Tech: XXX
Status: Pending
Priority: Medium
Application: xxx
Description: some issue
Resolution: some resolution
MIS Notes: some random stuff //p// followed by more stuff
Key Words:
Ticket No.: 20100426132
Ticket Date: 04/26/10, 10:22 AM
Close Date:
Primary User: XXX
Branch: XXX
Help Tech: XXX
Status: Pending
Priority: Medium
Application: xxx
Description: some issue
Resolution: some resolution
MIS Notes: //p//
Key Words:
Ticket No.: 20100426132
Ticket Date: 04/26/10, 10:22 AM
Close Date:
Primary User: XXX
Branch: XXX
Help Tech: XXX
Status: Pending
Priority: Medium
Application: xxx
Description: some issue
Resolution: some resolution
MIS Notes: //e// stuff....
Key Words:
Ticket No.: 20100426132
Ticket Date: 04/26/10, 10:22 AM
Close Date:
Primary User: XXX
Branch: XXX
Help Tech: XXX
Status: Pending
Priority: Medium
Application: xxx
Description: some issue
Resolution: some resolution
MIS Notes:
Key Words: