I somehow know that the answer to this question will be obvious, but I ve spent several days trying unsuccessfully to find out why I don t seem to be able to find the reg.exp. mach object in the script below. Here s the error messsage I get:
subject: Re: Why DOJ BMFEA Baton Rouge rejected Gonzalaz Pen Code 99999 death case
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Traceback (most recent call last):
File "C:AppsUtilitiesByMarc est_search4Sender_aaB.py", line 46, in <module>
print fn_cull_sender_info(date_string_raw)
File "C:AppsUtilitiesByMarc est_search4Sender_aaB.py", line 35, in fn_cull_sender_info
print Line 35: matchObj found
str(match_obj.group(0)) = + str(match_obj.group(0))
NameError: global name match_obj is not defined
该守则如下:
import sys
import re, pdb
#pdb.set_trace()
def fn_get_srctxt_hg_datestring_rawdata_from_clipbd():
this_scriptz_FULLName = sys.argv[0]
try:
date_string_raw = sys.argv[1]
return returnval
except:
date_string_raw =
import win32clipboard
win32clipboard.OpenClipboard()
clip_text = win32clipboard.GetClipboardData()
win32clipboard.CloseClipboard()
date_string_raw = clip_text
returnval = clip_text
return returnval
def fn_cull_sender_info(date_string_raw): #
# Do re replacements
import re
sender_info = Line 29 empty
print
Line 30: date_string_raw = [starts on next line...]
+ str(date_string_raw) +
+ x *80 +
srchpatrn = r"(from: )(([A-Za-z. ]+?)(?: ))?([A-Za-z.-_0-9]+@[A-Za-z.-_0-9].+?.(?:com|org|net))"
matchObj = re.search(srchpatrn, date_string_raw)
if matchObj:
print Line 35: matchObj found
str(match_obj.group(0)) = + str(match_obj.group(0))
sender_info = str(match_obj.group(0))
return sender_info
if __name__ == __main__ :
harvey = fn_get_srctxt_hg_datestring_rawdata_from_clipbd()
print harvey
date_string_raw = harvey
print ***** *50
print
print fn_cull_sender_info(date_string_raw)
下面(案文由另一个职能产生[此处没有显示])是我在“Windows C”记号板上掌握上述密码的案文:
sender_display_name = matchObj.search(date_string_raw).group(2)#.strip()
sender_eml = matchObj.search(date_string_raw).group(4)
I ve spent days trying to find out what I m doing wrong. I want to capture regular expression groups 3 and 4 into string variables, e.g.
但是,由于我可以拿着 match子回来,我无法回来。