5/11/2020

Python - re Module

** re Module - How to Write and Match Regular Expressions (Regex)


==========================================

print('\tTab')

print(r'\tTab')

---------------------------------

Tab
\tTab

---------------------------------

==========================================

import re

text_to_search = '''
abcdefghijklmnopqurtuvwxyz
ABCDEFGHIJKLMNOPQRSTUVWXYZ
1234567890
Ha HaHa
MetaCharacters (Need to be escaped):
. ^ $ * + ? { } [ ] \ | ( )
linuxerhan.com
321-555-4321
123.555.1234
123*555*1234
800-555-1234
900-555-1234
Mr. Schafer
Mr Smith
Ms Davis
Mrs. Robinson
Mr. T
'''

sentence = 'Start a sentence and then bring it to an end'

pattern = re.compile(r'abc')

matches = pattern.finditer(text_to_search)

for match in matches:
print(match)

---------------------------------

re.Match object; span=(1, 4), match='abc'

---------------------------------

==========================================

import re

text_to_search = '''
abcdefghijklmnopqurtuvwxyz
ABCDEFGHIJKLMNOPQRSTUVWXYZ
1234567890
Ha HaHa
MetaCharacters (Need to be escaped):
. ^ $ * + ? { } [ ] \ | ( )
linuxerhan.com
321-555-4321
123.555.1234
123*555*1234
800-555-1234
900-555-1234
Mr. Schafer
Mr Smith
Ms Davis
Mrs. Robinson
Mr. T
'''

sentence = 'Start a sentence and then bring it to an end'

pattern = re.compile(r'abc')

matches = pattern.finditer(text_to_search)

for match in matches:
print(match)

print(text_to_search[1:4])


---------------------------------

re.Match object; span=(1, 4), match='abc'
abc

---------------------------------


import re

text_to_search = '''
abcdefghijklmnopqurtuvwxyz
ABCDEFGHIJKLMNOPQRSTUVWXYZ
1234567890
Ha HaHa
MetaCharacters (Need to be escaped):
. ^ $ * + ? { } [ ] \ | ( )
linuxerhan.com
321-555-4321
123.555.1234
123*555*1234
800-555-1234
900-555-1234
Mr. Schafer
Mr Smith
Ms Davis
Mrs. Robinson
Mr. T
'''

sentence = 'Start a sentence and then bring it to an end'

pattern = re.compile(r'cba')

matches = pattern.finditer(text_to_search)

for match in matches:
print(match)

---------------------------------


---------------------------------


==========================================

import re

text_to_search = '''
abcdefghijklmnopqurtuvwxyz
ABCDEFGHIJKLMNOPQRSTUVWXYZ
1234567890
Ha HaHa
MetaCharacters (Need to be escaped):
. ^ $ * + ? { } [ ] \ | ( )
linuxerhan.com
321-555-4321
123.555.1234
123*555*1234
800-555-1234
900-555-1234
Mr. Schafer
Mr Smith
Ms Davis
Mrs. Robinson
Mr. T
'''

sentence = 'Start a sentence and then bring it to an end'

pattern = re.compile(r'.')

matches = pattern.finditer(text_to_search)

for match in matches:
print(match)

---------------------------------

re.Match object; span=(1, 2), match='a'
re.Match object; span=(2, 3), match='b'
re.Match object; span=(3, 4), match='c'
re.Match object; span=(4, 5), match='d'
re.Match object; span=(5, 6), match='e'
re.Match object; span=(6, 7), match='f'
re.Match object; span=(7, 8), match='g'
re.Match object; span=(8, 9), match='h'
re.Match object; span=(9, 10), match='i'
re.Match object; span=(10, 11), match='j'
re.Match object; span=(11, 12), match='k'
re.Match object; span=(12, 13), match='l'
re.Match object; span=(13, 14), match='m'
re.Match object; span=(14, 15), match='n'
re.Match object; span=(15, 16), match='o'
re.Match object; span=(16, 17), match='p'
re.Match object; span=(17, 18), match='q'
re.Match object; span=(18, 19), match='u'
re.Match object; span=(19, 20), match='r'
re.Match object; span=(20, 21), match='t'
re.Match object; span=(21, 22), match='u'
re.Match object; span=(22, 23), match='v'
re.Match object; span=(23, 24), match='w'
re.Match object; span=(24, 25), match='x'
re.Match object; span=(25, 26), match='y'
re.Match object; span=(26, 27), match='z'
re.Match object; span=(28, 29), match='A'
re.Match object; span=(29, 30), match='B'
re.Match object; span=(30, 31), match='C'
re.Match object; span=(31, 32), match='D'
re.Match object; span=(32, 33), match='E'
re.Match object; span=(33, 34), match='F'
re.Match object; span=(34, 35), match='G'
re.Match object; span=(35, 36), match='H'
re.Match object; span=(36, 37), match='I'
re.Match object; span=(37, 38), match='J'
re.Match object; span=(38, 39), match='K'
re.Match object; span=(39, 40), match='L'
re.Match object; span=(40, 41), match='M'
re.Match object; span=(41, 42), match='N'
re.Match object; span=(42, 43), match='O'
re.Match object; span=(43, 44), match='P'
re.Match object; span=(44, 45), match='Q'
re.Match object; span=(45, 46), match='R'
re.Match object; span=(46, 47), match='S'
re.Match object; span=(47, 48), match='T'
re.Match object; span=(48, 49), match='U'
re.Match object; span=(49, 50), match='V'
re.Match object; span=(50, 51), match='W'
re.Match object; span=(51, 52), match='X'
re.Match object; span=(52, 53), match='Y'
re.Match object; span=(53, 54), match='Z'
re.Match object; span=(55, 56), match='1'
re.Match object; span=(56, 57), match='2'
re.Match object; span=(57, 58), match='3'
re.Match object; span=(58, 59), match='4'
re.Match object; span=(59, 60), match='5'
re.Match object; span=(60, 61), match='6'
re.Match object; span=(61, 62), match='7'
re.Match object; span=(62, 63), match='8'
re.Match object; span=(63, 64), match='9'
re.Match object; span=(64, 65), match='0'
re.Match object; span=(66, 67), match='H'
re.Match object; span=(67, 68), match='a'
re.Match object; span=(68, 69), match=' '
re.Match object; span=(69, 70), match='H'
re.Match object; span=(70, 71), match='a'
re.Match object; span=(71, 72), match='H'
re.Match object; span=(72, 73), match='a'
re.Match object; span=(74, 75), match='M'
re.Match object; span=(75, 76), match='e'
re.Match object; span=(76, 77), match='t'
re.Match object; span=(77, 78), match='a'
re.Match object; span=(78, 79), match='C'
re.Match object; span=(79, 80), match='h'
re.Match object; span=(80, 81), match='a'
re.Match object; span=(81, 82), match='r'
re.Match object; span=(82, 83), match='a'
re.Match object; span=(83, 84), match='c'
re.Match object; span=(84, 85), match='t'
re.Match object; span=(85, 86), match='e'
re.Match object; span=(86, 87), match='r'
re.Match object; span=(87, 88), match='s'
re.Match object; span=(88, 89), match=' '
re.Match object; span=(89, 90), match='('
re.Match object; span=(90, 91), match='N'
re.Match object; span=(91, 92), match='e'
re.Match object; span=(92, 93), match='e'
re.Match object; span=(93, 94), match='d'
re.Match object; span=(94, 95), match=' '
re.Match object; span=(95, 96), match='t'
re.Match object; span=(96, 97), match='o'
re.Match object; span=(97, 98), match=' '
re.Match object; span=(98, 99), match='b'
re.Match object; span=(99, 100), match='e'
re.Match object; span=(100, 101), match=' '
re.Match object; span=(101, 102), match='e'
re.Match object; span=(102, 103), match='s'
re.Match object; span=(103, 104), match='c'
re.Match object; span=(104, 105), match='a'
re.Match object; span=(105, 106), match='p'
re.Match object; span=(106, 107), match='e'
re.Match object; span=(107, 108), match='d'
re.Match object; span=(108, 109), match=')'
re.Match object; span=(109, 110), match=':'
re.Match object; span=(111, 112), match='.'
re.Match object; span=(112, 113), match=' '
re.Match object; span=(113, 114), match='^'
re.Match object; span=(114, 115), match=' '
re.Match object; span=(115, 116), match='$'
re.Match object; span=(116, 117), match=' '
re.Match object; span=(117, 118), match='*'
re.Match object; span=(118, 119), match=' '
re.Match object; span=(119, 120), match='+'
re.Match object; span=(120, 121), match=' '
re.Match object; span=(121, 122), match='?'
re.Match object; span=(122, 123), match=' '
re.Match object; span=(123, 124), match='{'
re.Match object; span=(124, 125), match=' '
re.Match object; span=(125, 126), match='}'
re.Match object; span=(126, 127), match=' '
re.Match object; span=(127, 128), match='['
re.Match object; span=(128, 129), match=' '
re.Match object; span=(129, 130), match=']'
re.Match object; span=(130, 131), match=' '
re.Match object; span=(131, 132), match='\\'
re.Match object; span=(132, 133), match=' '
re.Match object; span=(133, 134), match='|'
re.Match object; span=(134, 135), match=' '
re.Match object; span=(135, 136), match='('
re.Match object; span=(136, 137), match=' '
re.Match object; span=(137, 138), match=')'
re.Match object; span=(139, 140), match='l'
re.Match object; span=(140, 141), match='i'
re.Match object; span=(141, 142), match='n'
re.Match object; span=(142, 143), match='u'
re.Match object; span=(143, 144), match='x'
re.Match object; span=(144, 145), match='e'
re.Match object; span=(145, 146), match='r'
re.Match object; span=(146, 147), match='h'
re.Match object; span=(147, 148), match='a'
re.Match object; span=(148, 149), match='n'
re.Match object; span=(149, 150), match='.'
re.Match object; span=(150, 151), match='c'
re.Match object; span=(151, 152), match='o'
re.Match object; span=(152, 153), match='m'
re.Match object; span=(154, 155), match='3'
re.Match object; span=(155, 156), match='2'
re.Match object; span=(156, 157), match='1'
re.Match object; span=(157, 158), match='-'
re.Match object; span=(158, 159), match='5'
re.Match object; span=(159, 160), match='5'
re.Match object; span=(160, 161), match='5'
re.Match object; span=(161, 162), match='-'
re.Match object; span=(162, 163), match='4'
re.Match object; span=(163, 164), match='3'
re.Match object; span=(164, 165), match='2'
re.Match object; span=(165, 166), match='1'
re.Match object; span=(167, 168), match='1'
re.Match object; span=(168, 169), match='2'
re.Match object; span=(169, 170), match='3'
re.Match object; span=(170, 171), match='.'
re.Match object; span=(171, 172), match='5'
re.Match object; span=(172, 173), match='5'
re.Match object; span=(173, 174), match='5'
re.Match object; span=(174, 175), match='.'
re.Match object; span=(175, 176), match='1'
re.Match object; span=(176, 177), match='2'
re.Match object; span=(177, 178), match='3'
re.Match object; span=(178, 179), match='4'
re.Match object; span=(180, 181), match='1'
re.Match object; span=(181, 182), match='2'
re.Match object; span=(182, 183), match='3'
re.Match object; span=(183, 184), match='*'
re.Match object; span=(184, 185), match='5'
re.Match object; span=(185, 186), match='5'
re.Match object; span=(186, 187), match='5'
re.Match object; span=(187, 188), match='*'
re.Match object; span=(188, 189), match='1'
re.Match object; span=(189, 190), match='2'
re.Match object; span=(190, 191), match='3'
re.Match object; span=(191, 192), match='4'
re.Match object; span=(193, 194), match='8'
re.Match object; span=(194, 195), match='0'
re.Match object; span=(195, 196), match='0'
re.Match object; span=(196, 197), match='-'
re.Match object; span=(197, 198), match='5'
re.Match object; span=(198, 199), match='5'
re.Match object; span=(199, 200), match='5'
re.Match object; span=(200, 201), match='-'
re.Match object; span=(201, 202), match='1'
re.Match object; span=(202, 203), match='2'
re.Match object; span=(203, 204), match='3'
re.Match object; span=(204, 205), match='4'
re.Match object; span=(206, 207), match='9'
re.Match object; span=(207, 208), match='0'
re.Match object; span=(208, 209), match='0'
re.Match object; span=(209, 210), match='-'
re.Match object; span=(210, 211), match='5'
re.Match object; span=(211, 212), match='5'
re.Match object; span=(212, 213), match='5'
re.Match object; span=(213, 214), match='-'
re.Match object; span=(214, 215), match='1'
re.Match object; span=(215, 216), match='2'
re.Match object; span=(216, 217), match='3'
re.Match object; span=(217, 218), match='4'
re.Match object; span=(219, 220), match='M'
re.Match object; span=(220, 221), match='r'
re.Match object; span=(221, 222), match='.'
re.Match object; span=(222, 223), match=' '
re.Match object; span=(223, 224), match='S'
re.Match object; span=(224, 225), match='c'
re.Match object; span=(225, 226), match='h'
re.Match object; span=(226, 227), match='a'
re.Match object; span=(227, 228), match='f'
re.Match object; span=(228, 229), match='e'
re.Match object; span=(229, 230), match='r'
re.Match object; span=(231, 232), match='M'
re.Match object; span=(232, 233), match='r'
re.Match object; span=(233, 234), match=' '
re.Match object; span=(234, 235), match='S'
re.Match object; span=(235, 236), match='m'
re.Match object; span=(236, 237), match='i'
re.Match object; span=(237, 238), match='t'
re.Match object; span=(238, 239), match='h'
re.Match object; span=(240, 241), match='M'
re.Match object; span=(241, 242), match='s'
re.Match object; span=(242, 243), match=' '
re.Match object; span=(243, 244), match='D'
re.Match object; span=(244, 245), match='a'
re.Match object; span=(245, 246), match='v'
re.Match object; span=(246, 247), match='i'
re.Match object; span=(247, 248), match='s'
re.Match object; span=(249, 250), match='M'
re.Match object; span=(250, 251), match='r'
re.Match object; span=(251, 252), match='s'
re.Match object; span=(252, 253), match='.'
re.Match object; span=(253, 254), match=' '
re.Match object; span=(254, 255), match='R'
re.Match object; span=(255, 256), match='o'
re.Match object; span=(256, 257), match='b'
re.Match object; span=(257, 258), match='i'
re.Match object; span=(258, 259), match='n'
re.Match object; span=(259, 260), match='s'
re.Match object; span=(260, 261), match='o'
re.Match object; span=(261, 262), match='n'
re.Match object; span=(263, 264), match='M'
re.Match object; span=(264, 265), match='r'
re.Match object; span=(265, 266), match='.'
re.Match object; span=(266, 267), match=' '
re.Match object; span=(267, 268), match='T'

---------------------------------

==========================================

import re

text_to_search = '''
abcdefghijklmnopqurtuvwxyz
ABCDEFGHIJKLMNOPQRSTUVWXYZ
1234567890
Ha HaHa
MetaCharacters (Need to be escaped):
. ^ $ * + ? { } [ ] \ | ( )
linuxerhan.com
321-555-4321
123.555.1234
123*555*1234
800-555-1234
900-555-1234
Mr. Schafer
Mr Smith
Ms Davis
Mrs. Robinson
Mr. T
'''

sentence = 'Start a sentence and then bring it to an end'

pattern = re.compile(r'\.')

matches = pattern.finditer(text_to_search)

for match in matches:
print(match)

---------------------------------

re.Match object; span=(111, 112), match='.'
re.Match object; span=(149, 150), match='.'
re.Match object; span=(170, 171), match='.'
re.Match object; span=(174, 175), match='.'
re.Match object; span=(221, 222), match='.'
re.Match object; span=(252, 253), match='.'
re.Match object; span=(265, 266), match='.'

---------------------------------


==========================================

import re

text_to_search = '''
abcdefghijklmnopqurtuvwxyz
ABCDEFGHIJKLMNOPQRSTUVWXYZ
1234567890
Ha HaHa
MetaCharacters (Need to be escaped):
. ^ $ * + ? { } [ ] \ | ( )
linuxerhan.com
321-555-4321
123.555.1234
123*555*1234
800-555-1234
900-555-1234
Mr. Schafer
Mr Smith
Ms Davis
Mrs. Robinson
Mr. T
'''

sentence = 'Start a sentence and then bring it to an end'

pattern = re.compile(r'linuxerhan\.com')

matches = pattern.finditer(text_to_search)

for match in matches:
print(match)

---------------------------------

re.Match object; span=(139, 153), match='linuxerhan.com'


---------------------------------

==========================================







==========================================

import re

pattern = re.compile(r'\d\d\d.\d\d\d.\d\d\d\d')

with open('data.txt', 'r', encoding = 'utf-8') as f:
contents = f.read()

matches = pattern.finditer(contents)

for match in matches:
print(match)

---------------------------------

re.Match object; span=(12, 24), match='615-555-7164'
re.Match object; span=(102, 114), match='800-555-5669'
re.Match object; span=(191, 203), match='560-555-5153'
re.Match object; span=(281, 293), match='900-555-9340'
re.Match object; span=(378, 390), match='714-555-7405'
re.Match object; span=(467, 479), match='800-555-6771'
re.Match object; span=(557, 569), match='783-555-4799'
re.Match object; span=(647, 659), match='516-555-4615'
re.Match object; span=(740, 752), match='127-555-1867'
re.Match object; span=(829, 841), match='608-555-4938'
re.Match object; span=(915, 927), match='568-555-6051'
re.Match object; span=(1003, 1015), match='292-555-1875'
re.Match object; span=(1091, 1103), match='900-555-3205'
re.Match object; span=(1180, 1192), match='614-555-1166'
re.Match object; span=(1269, 1281), match='530-555-2676'
re.Match object; span=(1355, 1367), match='470-555-2750'
re.Match object; span=(1439, 1451), match='800-555-6089'
re.Match object; span=(1526, 1538), match='880-555-8319'
re.Match object; span=(1614, 1626), match='777-555-8378'
re.Match object; span=(1697, 1709), match='998-555-7385'
re.Match object; span=(1790, 1802), match='800-555-7100'
re.Match object; span=(1874, 1886), match='903-555-8277'
re.Match object; span=(1962, 1974), match='196-555-5674'
re.Match object; span=(2051, 2063), match='900-555-5118'
re.Match object; span=(2135, 2147), match='905-555-1630'
re.Match object; span=(2216, 2228), match='203-555-3475'
re.Match object; span=(2300, 2312), match='884-555-8444'
re.Match object; span=(2387, 2399), match='904-555-8559'
re.Match object; span=(2475, 2487), match='889-555-7393'
re.Match object; span=(2562, 2574), match='195-555-2405'
re.Match object; span=(2647, 2659), match='321-555-9053'
re.Match object; span=(2734, 2746), match='133-555-1711'
re.Match object; span=(2826, 2838), match='900-555-5428'
re.Match object; span=(2915, 2927), match='760-555-7147'
re.Match object; span=(3012, 3024), match='391-555-6621'
re.Match object; span=(3103, 3115), match='932-555-7724'
re.Match object; span=(3192, 3204), match='609-555-7908'
re.Match object; span=(3284, 3296), match='800-555-8810'
re.Match object; span=(3372, 3384), match='149-555-7657'
re.Match object; span=(3452, 3464), match='130-555-9709'
re.Match object; span=(3535, 3547), match='143-555-9295'
re.Match object; span=(3624, 3636), match='903-555-9878'
re.Match object; span=(3714, 3726), match='574-555-3194'
re.Match object; span=(3802, 3814), match='496-555-7533'
re.Match object; span=(3887, 3899), match='210-555-3757'
re.Match object; span=(3971, 3983), match='900-555-9598'
re.Match object; span=(4056, 4068), match='866-555-9844'
re.Match object; span=(4140, 4152), match='669-555-7159'
re.Match object; span=(4225, 4237), match='152-555-7417'
re.Match object; span=(4317, 4329), match='893-555-9832'
re.Match object; span=(4407, 4419), match='217-555-7123'
re.Match object; span=(4498, 4510), match='786-555-6544'
re.Match object; span=(4588, 4600), match='780-555-2574'
re.Match object; span=(4676, 4688), match='926-555-8735'
re.Match object; span=(4762, 4774), match='895-555-3539'
re.Match object; span=(4859, 4871), match='874-555-3949'
re.Match object; span=(4945, 4957), match='800-555-2420'
re.Match object; span=(5034, 5046), match='936-555-6340'
re.Match object; span=(5123, 5135), match='372-555-9809'
re.Match object; span=(5210, 5222), match='890-555-5618'
re.Match object; span=(5292, 5304), match='670-555-3005'
re.Match object; span=(5382, 5394), match='509-555-5997'
re.Match object; span=(5475, 5487), match='721-555-5632'
re.Match object; span=(5566, 5578), match='900-555-3567'
re.Match object; span=(5656, 5668), match='147-555-6830'
re.Match object; span=(5745, 5757), match='582-555-3426'
re.Match object; span=(5830, 5842), match='400-555-1706'
re.Match object; span=(5921, 5933), match='525-555-1793'
re.Match object; span=(6011, 6023), match='317-555-6700'
re.Match object; span=(6099, 6111), match='974-555-8301'
re.Match object; span=(6189, 6201), match='800-555-3216'
re.Match object; span=(6273, 6285), match='746-555-4094'
re.Match object; span=(6360, 6372), match='922-555-1773'
re.Match object; span=(6445, 6457), match='711-555-4427'
re.Match object; span=(6530, 6542), match='355-555-1872'
re.Match object; span=(6619, 6631), match='852-555-6521'
re.Match object; span=(6711, 6723), match='691-555-5773'
re.Match object; span=(6803, 6815), match='332-555-5441'
re.Match object; span=(6889, 6901), match='900-555-7755'
re.Match object; span=(6971, 6983), match='379-555-3685'
re.Match object; span=(7061, 7073), match='127-555-9682'
re.Match object; span=(7152, 7164), match='789-555-7032'
re.Match object; span=(7243, 7255), match='783-555-5135'
re.Match object; span=(7336, 7348), match='315-555-6507'
re.Match object; span=(7427, 7439), match='481-555-5835'
re.Match object; span=(7515, 7527), match='365-555-8287'
re.Match object; span=(7607, 7619), match='911-555-7535'
re.Match object; span=(7693, 7705), match='681-555-2460'
re.Match object; span=(7779, 7791), match='274-555-9800'
re.Match object; span=(7864, 7876), match='800-555-1372'
re.Match object; span=(7953, 7965), match='300-555-7821'
re.Match object; span=(8043, 8055), match='133-555-3889'
re.Match object; span=(8129, 8141), match='705-555-6863'
re.Match object; span=(8218, 8230), match='215-555-9449'
re.Match object; span=(8309, 8321), match='988-555-6112'
re.Match object; span=(8395, 8407), match='623-555-3006'
re.Match object; span=(8479, 8491), match='192-555-4977'
re.Match object; span=(8564, 8576), match='178-555-4899'
re.Match object; span=(8648, 8660), match='952-555-3089'
re.Match object; span=(8741, 8753), match='900-555-6426'


---------------------------------

321-555-4321
123.555.1234
123*555*1234
800-555-1234
900-555-1234

==========================================

pattern = re.compile(r'\d\d\d[-.]\d\d\d[-.]\d\d\d\d')

---------------------------------

re.Match object; span=(154, 166), match='321-555-4321'
re.Match object; span=(167, 179), match='123.555.1234'
re.Match object; span=(193, 205), match='800-555-1234'
re.Match object; span=(206, 218), match='900-555-1234'

---------------------------------

pattern = re.compile(r'[89]00[-.]\d\d\d[-.]\d\d\d\d')

---------------------------------

re.Match object; span=(194, 206), match='800-555-1234'
re.Match object; span=(207, 219), match='900-555-1234'

---------------------------------

==========================================

import re

text_to_search = '''
abcdefghijklmnopqurtuvwxyz
ABCDEFGHIJKLMNOPQRSTUVWXYZ
1234567890
Ha HaHa
MetaCharacters (Need to be escaped):
. ^ $ * + ? { } [ ] \ | ( )

linuxerhan.com

321--555-4321
123.555.1234
123*555*1234
800-555-1234
900-555-1234

Mr. Schafer
Mr Smith
Ms Davis
Mrs. Robinson
Mr. T

cat
mat
pat
bat

'''


sentence = 'Start a sentence and then bring it to an end'

pattern = re.compile(r'[^b]at')

matches = pattern.finditer(text_to_search)


for match in matches:
print(match)

---------------------------------

re.Match object; span=(274, 277), match='cat'
re.Match object; span=(278, 281), match='mat'
re.Match object; span=(282, 285), match='pat'

---------------------------------

==========================================


==========================================

import re

text_to_search = '''
abcdefghijklmnopqurtuvwxyz
ABCDEFGHIJKLMNOPQRSTUVWXYZ
1234567890
Ha HaHa
MetaCharacters (Need to be escaped):
. ^ $ * + ? { } [ ] \ | ( )

linuxerhan.com

321--555-4321
123.555.1234
123*555*1234
800-555-1234
900-555-1234

Mr. Schafer
Mr Smith
Ms Davis
Mrs. Robinson
Mr. T
'''

sentence = 'Start a sentence and then bring it to an end'

pattern = re.compile(r'[1-5]')

matches = pattern.finditer(text_to_search)


for match in matches:
print(match)


---------------------------------

re.Match object; span=(55, 56), match='1'
re.Match object; span=(56, 57), match='2'
re.Match object; span=(57, 58), match='3'
re.Match object; span=(58, 59), match='4'
re.Match object; span=(59, 60), match='5'
re.Match object; span=(154, 155), match='3'
re.Match object; span=(155, 156), match='2'
re.Match object; span=(156, 157), match='1'
re.Match object; span=(159, 160), match='5'
re.Match object; span=(160, 161), match='5'
re.Match object; span=(161, 162), match='5'
re.Match object; span=(163, 164), match='4'
re.Match object; span=(164, 165), match='3'
re.Match object; span=(165, 166), match='2'
re.Match object; span=(166, 167), match='1'
re.Match object; span=(168, 169), match='1'
re.Match object; span=(169, 170), match='2'
re.Match object; span=(170, 171), match='3'
re.Match object; span=(172, 173), match='5'
re.Match object; span=(173, 174), match='5'
re.Match object; span=(174, 175), match='5'
re.Match object; span=(176, 177), match='1'
re.Match object; span=(177, 178), match='2'
re.Match object; span=(178, 179), match='3'
re.Match object; span=(179, 180), match='4'
re.Match object; span=(181, 182), match='1'
re.Match object; span=(182, 183), match='2'
re.Match object; span=(183, 184), match='3'
re.Match object; span=(185, 186), match='5'
re.Match object; span=(186, 187), match='5'
re.Match object; span=(187, 188), match='5'
re.Match object; span=(189, 190), match='1'
re.Match object; span=(190, 191), match='2'
re.Match object; span=(191, 192), match='3'
re.Match object; span=(192, 193), match='4'
re.Match object; span=(198, 199), match='5'
re.Match object; span=(199, 200), match='5'
re.Match object; span=(200, 201), match='5'
re.Match object; span=(202, 203), match='1'
re.Match object; span=(203, 204), match='2'
re.Match object; span=(204, 205), match='3'
re.Match object; span=(205, 206), match='4'
re.Match object; span=(211, 212), match='5'
re.Match object; span=(212, 213), match='5'
re.Match object; span=(213, 214), match='5'
re.Match object; span=(215, 216), match='1'
re.Match object; span=(216, 217), match='2'
re.Match object; span=(217, 218), match='3'
re.Match object; span=(218, 219), match='4'

---------------------------------

pattern = re.compile(r'[a-z]')

---------------------------------

re.Match object; span=(1, 2), match='a'
re.Match object; span=(2, 3), match='b'
re.Match object; span=(3, 4), match='c'
re.Match object; span=(4, 5), match='d'
re.Match object; span=(5, 6), match='e'
re.Match object; span=(6, 7), match='f'
re.Match object; span=(7, 8), match='g'
re.Match object; span=(8, 9), match='h'
re.Match object; span=(9, 10), match='i'
re.Match object; span=(10, 11), match='j'
re.Match object; span=(11, 12), match='k'
re.Match object; span=(12, 13), match='l'
re.Match object; span=(13, 14), match='m'
re.Match object; span=(14, 15), match='n'
re.Match object; span=(15, 16), match='o'
re.Match object; span=(16, 17), match='p'
re.Match object; span=(17, 18), match='q'
re.Match object; span=(18, 19), match='u'
re.Match object; span=(19, 20), match='r'
re.Match object; span=(20, 21), match='t'
re.Match object; span=(21, 22), match='u'
re.Match object; span=(22, 23), match='v'
re.Match object; span=(23, 24), match='w'
re.Match object; span=(24, 25), match='x'
re.Match object; span=(25, 26), match='y'
re.Match object; span=(26, 27), match='z'
re.Match object; span=(67, 68), match='a'
re.Match object; span=(70, 71), match='a'
re.Match object; span=(72, 73), match='a'
re.Match object; span=(75, 76), match='e'
re.Match object; span=(76, 77), match='t'
re.Match object; span=(77, 78), match='a'
re.Match object; span=(79, 80), match='h'
re.Match object; span=(80, 81), match='a'
re.Match object; span=(81, 82), match='r'
re.Match object; span=(82, 83), match='a'
re.Match object; span=(83, 84), match='c'
re.Match object; span=(84, 85), match='t'
re.Match object; span=(85, 86), match='e'
re.Match object; span=(86, 87), match='r'
re.Match object; span=(87, 88), match='s'
re.Match object; span=(91, 92), match='e'
re.Match object; span=(92, 93), match='e'
re.Match object; span=(93, 94), match='d'
re.Match object; span=(95, 96), match='t'
re.Match object; span=(96, 97), match='o'
re.Match object; span=(98, 99), match='b'
re.Match object; span=(99, 100), match='e'
re.Match object; span=(101, 102), match='e'
re.Match object; span=(102, 103), match='s'
re.Match object; span=(103, 104), match='c'
re.Match object; span=(104, 105), match='a'
re.Match object; span=(105, 106), match='p'
re.Match object; span=(106, 107), match='e'
re.Match object; span=(107, 108), match='d'
re.Match object; span=(139, 140), match='l'
re.Match object; span=(140, 141), match='i'
re.Match object; span=(141, 142), match='n'
re.Match object; span=(142, 143), match='u'
re.Match object; span=(143, 144), match='x'
re.Match object; span=(144, 145), match='e'
re.Match object; span=(145, 146), match='r'
re.Match object; span=(146, 147), match='h'
re.Match object; span=(147, 148), match='a'
re.Match object; span=(148, 149), match='n'
re.Match object; span=(150, 151), match='c'
re.Match object; span=(151, 152), match='o'
re.Match object; span=(152, 153), match='m'
re.Match object; span=(221, 222), match='r'
re.Match object; span=(225, 226), match='c'
re.Match object; span=(226, 227), match='h'
re.Match object; span=(227, 228), match='a'
re.Match object; span=(228, 229), match='f'
re.Match object; span=(229, 230), match='e'
re.Match object; span=(230, 231), match='r'
re.Match object; span=(233, 234), match='r'
re.Match object; span=(236, 237), match='m'
re.Match object; span=(237, 238), match='i'
re.Match object; span=(238, 239), match='t'
re.Match object; span=(239, 240), match='h'
re.Match object; span=(242, 243), match='s'
re.Match object; span=(245, 246), match='a'
re.Match object; span=(246, 247), match='v'
re.Match object; span=(247, 248), match='i'
re.Match object; span=(248, 249), match='s'
re.Match object; span=(251, 252), match='r'
re.Match object; span=(252, 253), match='s'
re.Match object; span=(256, 257), match='o'
re.Match object; span=(257, 258), match='b'
re.Match object; span=(258, 259), match='i'
re.Match object; span=(259, 260), match='n'
re.Match object; span=(260, 261), match='s'
re.Match object; span=(261, 262), match='o'
re.Match object; span=(262, 263), match='n'
re.Match object; span=(265, 266), match='r'

---------------------------------

pattern = re.compile(r'[a-zA-Z]')

---------------------------------
re.Match object; span=(1, 2), match='a'
re.Match object; span=(2, 3), match='b'
re.Match object; span=(3, 4), match='c'
re.Match object; span=(4, 5), match='d'
re.Match object; span=(5, 6), match='e'
re.Match object; span=(6, 7), match='f'
re.Match object; span=(7, 8), match='g'
re.Match object; span=(8, 9), match='h'
re.Match object; span=(9, 10), match='i'
re.Match object; span=(10, 11), match='j'
re.Match object; span=(11, 12), match='k'
re.Match object; span=(12, 13), match='l'
re.Match object; span=(13, 14), match='m'
re.Match object; span=(14, 15), match='n'
re.Match object; span=(15, 16), match='o'
re.Match object; span=(16, 17), match='p'
re.Match object; span=(17, 18), match='q'
re.Match object; span=(18, 19), match='u'
re.Match object; span=(19, 20), match='r'
re.Match object; span=(20, 21), match='t'
re.Match object; span=(21, 22), match='u'
re.Match object; span=(22, 23), match='v'
re.Match object; span=(23, 24), match='w'
re.Match object; span=(24, 25), match='x'
re.Match object; span=(25, 26), match='y'
re.Match object; span=(26, 27), match='z'
re.Match object; span=(28, 29), match='A'
re.Match object; span=(29, 30), match='B'
re.Match object; span=(30, 31), match='C'
re.Match object; span=(31, 32), match='D'
re.Match object; span=(32, 33), match='E'
re.Match object; span=(33, 34), match='F'
re.Match object; span=(34, 35), match='G'
re.Match object; span=(35, 36), match='H'
re.Match object; span=(36, 37), match='I'
re.Match object; span=(37, 38), match='J'
re.Match object; span=(38, 39), match='K'
re.Match object; span=(39, 40), match='L'
re.Match object; span=(40, 41), match='M'
re.Match object; span=(41, 42), match='N'
re.Match object; span=(42, 43), match='O'
re.Match object; span=(43, 44), match='P'
re.Match object; span=(44, 45), match='Q'
re.Match object; span=(45, 46), match='R'
re.Match object; span=(46, 47), match='S'
re.Match object; span=(47, 48), match='T'
re.Match object; span=(48, 49), match='U'
re.Match object; span=(49, 50), match='V'
re.Match object; span=(50, 51), match='W'
re.Match object; span=(51, 52), match='X'
re.Match object; span=(52, 53), match='Y'
re.Match object; span=(53, 54), match='Z'
re.Match object; span=(66, 67), match='H'
re.Match object; span=(67, 68), match='a'
re.Match object; span=(69, 70), match='H'
re.Match object; span=(70, 71), match='a'
re.Match object; span=(71, 72), match='H'
re.Match object; span=(72, 73), match='a'
re.Match object; span=(74, 75), match='M'
re.Match object; span=(75, 76), match='e'
re.Match object; span=(76, 77), match='t'
re.Match object; span=(77, 78), match='a'
re.Match object; span=(78, 79), match='C'
re.Match object; span=(79, 80), match='h'
re.Match object; span=(80, 81), match='a'
re.Match object; span=(81, 82), match='r'
re.Match object; span=(82, 83), match='a'
re.Match object; span=(83, 84), match='c'
re.Match object; span=(84, 85), match='t'
re.Match object; span=(85, 86), match='e'
re.Match object; span=(86, 87), match='r'
re.Match object; span=(87, 88), match='s'
re.Match object; span=(90, 91), match='N'
re.Match object; span=(91, 92), match='e'
re.Match object; span=(92, 93), match='e'
re.Match object; span=(93, 94), match='d'
re.Match object; span=(95, 96), match='t'
re.Match object; span=(96, 97), match='o'
re.Match object; span=(98, 99), match='b'
re.Match object; span=(99, 100), match='e'
re.Match object; span=(101, 102), match='e'
re.Match object; span=(102, 103), match='s'
re.Match object; span=(103, 104), match='c'
re.Match object; span=(104, 105), match='a'
re.Match object; span=(105, 106), match='p'
re.Match object; span=(106, 107), match='e'
re.Match object; span=(107, 108), match='d'
re.Match object; span=(139, 140), match='l'
re.Match object; span=(140, 141), match='i'
re.Match object; span=(141, 142), match='n'
re.Match object; span=(142, 143), match='u'
re.Match object; span=(143, 144), match='x'
re.Match object; span=(144, 145), match='e'
re.Match object; span=(145, 146), match='r'
re.Match object; span=(146, 147), match='h'
re.Match object; span=(147, 148), match='a'
re.Match object; span=(148, 149), match='n'
re.Match object; span=(150, 151), match='c'
re.Match object; span=(151, 152), match='o'
re.Match object; span=(152, 153), match='m'
re.Match object; span=(220, 221), match='M'
re.Match object; span=(221, 222), match='r'
re.Match object; span=(224, 225), match='S'
re.Match object; span=(225, 226), match='c'
re.Match object; span=(226, 227), match='h'
re.Match object; span=(227, 228), match='a'
re.Match object; span=(228, 229), match='f'
re.Match object; span=(229, 230), match='e'
re.Match object; span=(230, 231), match='r'
re.Match object; span=(232, 233), match='M'
re.Match object; span=(233, 234), match='r'
re.Match object; span=(235, 236), match='S'
re.Match object; span=(236, 237), match='m'
re.Match object; span=(237, 238), match='i'
re.Match object; span=(238, 239), match='t'
re.Match object; span=(239, 240), match='h'
re.Match object; span=(241, 242), match='M'
re.Match object; span=(242, 243), match='s'
re.Match object; span=(244, 245), match='D'
re.Match object; span=(245, 246), match='a'
re.Match object; span=(246, 247), match='v'
re.Match object; span=(247, 248), match='i'
re.Match object; span=(248, 249), match='s'
re.Match object; span=(250, 251), match='M'
re.Match object; span=(251, 252), match='r'
re.Match object; span=(252, 253), match='s'
re.Match object; span=(255, 256), match='R'
re.Match object; span=(256, 257), match='o'
re.Match object; span=(257, 258), match='b'
re.Match object; span=(258, 259), match='i'
re.Match object; span=(259, 260), match='n'
re.Match object; span=(260, 261), match='s'
re.Match object; span=(261, 262), match='o'
re.Match object; span=(262, 263), match='n'
re.Match object; span=(264, 265), match='M'
re.Match object; span=(265, 266), match='r'
re.Match object; span=(268, 269), match='T'

---------------------------------

pattern = re.compile(r'[^a-zA-Z]')

---------------------------------

re.Match object; span=(0, 1), match='\n'
re.Match object; span=(27, 28), match='\n'
re.Match object; span=(54, 55), match='\n'
re.Match object; span=(55, 56), match='1'
re.Match object; span=(56, 57), match='2'
re.Match object; span=(57, 58), match='3'
re.Match object; span=(58, 59), match='4'
re.Match object; span=(59, 60), match='5'
re.Match object; span=(60, 61), match='6'
re.Match object; span=(61, 62), match='7'
re.Match object; span=(62, 63), match='8'
re.Match object; span=(63, 64), match='9'
re.Match object; span=(64, 65), match='0'
re.Match object; span=(65, 66), match='\n'
re.Match object; span=(68, 69), match=' '
re.Match object; span=(73, 74), match='\n'
re.Match object; span=(88, 89), match=' '
re.Match object; span=(89, 90), match='('
re.Match object; span=(94, 95), match=' '
re.Match object; span=(97, 98), match=' '
re.Match object; span=(100, 101), match=' '
re.Match object; span=(108, 109), match=')'
re.Match object; span=(109, 110), match=':'
re.Match object; span=(110, 111), match='\n'
re.Match object; span=(111, 112), match='.'
re.Match object; span=(112, 113), match=' '
re.Match object; span=(113, 114), match='^'
re.Match object; span=(114, 115), match=' '
re.Match object; span=(115, 116), match='$'
re.Match object; span=(116, 117), match=' '
re.Match object; span=(117, 118), match='*'
re.Match object; span=(118, 119), match=' '
re.Match object; span=(119, 120), match='+'
re.Match object; span=(120, 121), match=' '
re.Match object; span=(121, 122), match='?'
re.Match object; span=(122, 123), match=' '
re.Match object; span=(123, 124), match='{'
re.Match object; span=(124, 125), match=' '
re.Match object; span=(125, 126), match='}'
re.Match object; span=(126, 127), match=' '
re.Match object; span=(127, 128), match='['
re.Match object; span=(128, 129), match=' '
re.Match object; span=(129, 130), match=']'
re.Match object; span=(130, 131), match=' '
re.Match object; span=(131, 132), match='\\'
re.Match object; span=(132, 133), match=' '
re.Match object; span=(133, 134), match='|'
re.Match object; span=(134, 135), match=' '
re.Match object; span=(135, 136), match='('
re.Match object; span=(136, 137), match=' '
re.Match object; span=(137, 138), match=')'
re.Match object; span=(138, 139), match='\n'
re.Match object; span=(149, 150), match='.'
re.Match object; span=(153, 154), match='\n'
re.Match object; span=(154, 155), match='3'
re.Match object; span=(155, 156), match='2'
re.Match object; span=(156, 157), match='1'
re.Match object; span=(157, 158), match='-'
re.Match object; span=(158, 159), match='-'
re.Match object; span=(159, 160), match='5'
re.Match object; span=(160, 161), match='5'
re.Match object; span=(161, 162), match='5'
re.Match object; span=(162, 163), match='-'
re.Match object; span=(163, 164), match='4'
re.Match object; span=(164, 165), match='3'
re.Match object; span=(165, 166), match='2'
re.Match object; span=(166, 167), match='1'
re.Match object; span=(167, 168), match='\n'
re.Match object; span=(168, 169), match='1'
re.Match object; span=(169, 170), match='2'
re.Match object; span=(170, 171), match='3'
re.Match object; span=(171, 172), match='.'
re.Match object; span=(172, 173), match='5'
re.Match object; span=(173, 174), match='5'
re.Match object; span=(174, 175), match='5'
re.Match object; span=(175, 176), match='.'
re.Match object; span=(176, 177), match='1'
re.Match object; span=(177, 178), match='2'
re.Match object; span=(178, 179), match='3'
re.Match object; span=(179, 180), match='4'
re.Match object; span=(180, 181), match='\n'
re.Match object; span=(181, 182), match='1'
re.Match object; span=(182, 183), match='2'
re.Match object; span=(183, 184), match='3'
re.Match object; span=(184, 185), match='*'
re.Match object; span=(185, 186), match='5'
re.Match object; span=(186, 187), match='5'
re.Match object; span=(187, 188), match='5'
re.Match object; span=(188, 189), match='*'
re.Match object; span=(189, 190), match='1'
re.Match object; span=(190, 191), match='2'
re.Match object; span=(191, 192), match='3'
re.Match object; span=(192, 193), match='4'
re.Match object; span=(193, 194), match='\n'
re.Match object; span=(194, 195), match='8'
re.Match object; span=(195, 196), match='0'
re.Match object; span=(196, 197), match='0'
re.Match object; span=(197, 198), match='-'
re.Match object; span=(198, 199), match='5'
re.Match object; span=(199, 200), match='5'
re.Match object; span=(200, 201), match='5'
re.Match object; span=(201, 202), match='-'
re.Match object; span=(202, 203), match='1'
re.Match object; span=(203, 204), match='2'
re.Match object; span=(204, 205), match='3'
re.Match object; span=(205, 206), match='4'
re.Match object; span=(206, 207), match='\n'
re.Match object; span=(207, 208), match='9'
re.Match object; span=(208, 209), match='0'
re.Match object; span=(209, 210), match='0'
re.Match object; span=(210, 211), match='-'
re.Match object; span=(211, 212), match='5'
re.Match object; span=(212, 213), match='5'
re.Match object; span=(213, 214), match='5'
re.Match object; span=(214, 215), match='-'
re.Match object; span=(215, 216), match='1'
re.Match object; span=(216, 217), match='2'
re.Match object; span=(217, 218), match='3'
re.Match object; span=(218, 219), match='4'
re.Match object; span=(219, 220), match='\n'
re.Match object; span=(222, 223), match='.'
re.Match object; span=(223, 224), match=' '
re.Match object; span=(231, 232), match='\n'
re.Match object; span=(234, 235), match=' '
re.Match object; span=(240, 241), match='\n'
re.Match object; span=(243, 244), match=' '
re.Match object; span=(249, 250), match='\n'
re.Match object; span=(253, 254), match='.'
re.Match object; span=(254, 255), match=' '
re.Match object; span=(263, 264), match='\n'
re.Match object; span=(266, 267), match='.'
re.Match object; span=(267, 268), match=' '
re.Match object; span=(269, 270), match='\n'

---------------------------------

pattern = re.compile(r'\d\d\d.\d\d\d.\d\d\d\d')

---------------------------------

re.Match object; span=(170, 182), match='123.555.1234'
re.Match object; span=(183, 195), match='123*555*1234'
re.Match object; span=(196, 208), match='800-555-1234'
re.Match object; span=(209, 221), match='900-555-1234'

---------------------------------

==========================================

import re

text_to_search = '''
abcdefghijklmnopqurtuvwxyz
ABCDEFGHIJKLMNOPQRSTUVWXYZ
1234567890
Ha HaHa
MetaCharacters (Need to be escaped):
. ^ $ * + ? { } [ ] \ | ( )

linuxerhan.com

321-555-4321
123.555.1234
123*555*1234
800-555-1234
900-555-1234

Mr. Schafer
Mr Smith
Ms Davis
Mrs. Robinson
Mr. T
'''


sentence = 'Start a sentence and then bring it to an end'

pattern = re.compile(r'\d{3}.\d{3}.\d{4}')

matches = pattern.finditer(text_to_search)


for match in matches:
print(match)

---------------------------------

re.Match object; span=(156, 168), match='321-555-4321'
re.Match object; span=(169, 181), match='123.555.1234'
re.Match object; span=(182, 194), match='123*555*1234'
re.Match object; span=(195, 207), match='800-555-1234'
re.Match object; span=(208, 220), match='900-555-1234'

---------------------------------

pattern = re.compile(r'Mr\.')

---------------------------------

re.Match object; span=(222, 225), match='Mr.'
re.Match object; span=(266, 269), match='Mr.'

---------------------------------

pattern = re.compile(r'Mr\.?')

---------------------------------

re.Match object; span=(222, 225), match='Mr.'
re.Match object; span=(234, 236), match='Mr'
re.Match object; span=(252, 254), match='Mr'
re.Match object; span=(266, 269), match='Mr.'

---------------------------------

pattern = re.compile(r'Mr\.?\s[A-Z]')

---------------------------------

re.Match object; span=(222, 227), match='Mr. S'
re.Match object; span=(234, 238), match='Mr S'
re.Match object; span=(266, 271), match='Mr. T'

---------------------------------

pattern = re.compile(r'Mr\.?\s[A-Z]\w+')

---------------------------------

re.Match object; span=(222, 233), match='Mr. Schafer'
re.Match object; span=(234, 242), match='Mr Smith'

---------------------------------

pattern = re.compile(r'Mr\.?\s[A-Z]\w*')

---------------------------------

re.Match object; span=(222, 233), match='Mr. Schafer'
re.Match object; span=(234, 242), match='Mr Smith'
re.Match object; span=(266, 271), match='Mr. T'

---------------------------------

pattern = re.compile(r'M(r|s|rs)\.?\s[A-Z]\w*')

---------------------------------

re.Match object; span=(222, 233), match='Mr. Schafer'
re.Match object; span=(234, 242), match='Mr Smith'
re.Match object; span=(243, 251), match='Ms Davis'
re.Match object; span=(252, 265), match='Mrs. Robinson'
re.Match object; span=(266, 271), match='Mr. T'

---------------------------------

pattern = re.compile(r'(Mr|Ms|Mrs)\.?\s[A-Z]\w*')

---------------------------------

re.Match object; span=(222, 233), match='Mr. Schafer'
re.Match object; span=(234, 242), match='Mr Smith'
re.Match object; span=(243, 251), match='Ms Davis'
re.Match object; span=(252, 265), match='Mrs. Robinson'
re.Match object; span=(266, 271), match='Mr. T'

---------------------------------

==========================================


import re

emails = '''
CoreyMSchafer@gmail.com
corey.schafer@university.edu
corey-321-schafer@my-work.net
'''

pattern = re.compile(r'[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+')

matches = pattern.finditer(emails)

for match in matches:
    print(match)


---------------------------------

re.Match object; span=(1, 24), match='CoreyMSchafer@gmail.com'
re.Match object; span=(25, 53), match='corey.schafer@university.edu'
re.Match object; span=(54, 83), match='corey-321-schafer@my-work.net'

---------------------------------

pattern = re.compile(r'[a-zA-Z]+@[a-zA-Z]+\.com')

---------------------------------

re.Match object; span=(1, 24), match='CoreyMSchafer@gmail.com'

---------------------------------

pattern = re.compile(r'[a-zA-Z.]+@[a-zA-Z]+\.(com|edu)')

---------------------------------

re.Match object; span=(1, 24), match='CoreyMSchafer@gmail.com'
re.Match object; span=(25, 53), match='corey.schafer@university.edu'

---------------------------------

pattern = re.compile(r'[a-zA-Z0-9.-]+@[a-zA-Z-]+\.(com|edu|net)')

---------------------------------

re.Match object; span=(1, 24), match='CoreyMSchafer@gmail.com'
re.Match object; span=(25, 53), match='corey.schafer@university.edu'
re.Match object; span=(54, 83), match='corey-321-schafer@my-work.net'

---------------------------------

pattern = re.compile(r'[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+')

---------------------------------

re.Match object; span=(1, 24), match='CoreyMSchafer@gmail.com'
re.Match object; span=(25, 53), match='corey.schafer@university.edu'
re.Match object; span=(54, 83), match='corey-321-schafer@my-work.net'

---------------------------------

==========================================

import re

urls = '''
https://www.google.com
http://blogspot.com
https://youtube.com
https://www.nasa.gov
'''

pattern = re.compile(r'https?://(www\.)?')

matches = pattern.finditer(urls)

for match in matches:
print(match)

---------------------------------

re.Match object; span=(1, 13), match='https://www.'
re.Match object; span=(24, 31), match='http://'
re.Match object; span=(44, 52), match='https://'
re.Match object; span=(64, 76), match='https://www.'

---------------------------------

pattern = re.compile(r'https?://(www\.)?\w+\.\w+')

---------------------------------

re.Match object; span=(1, 23), match='https://www.google.com'
re.Match object; span=(24, 43), match='http://blogspot.com'
re.Match object; span=(44, 63), match='https://youtube.com'
re.Match object; span=(64, 84), match='https://www.nasa.gov'

---------------------------------

pattern = re.compile(r'https?://(www\.)?(\w+)(\.\w+)')

---------------------------------

re.Match object; span=(1, 23), match='https://www.google.com'
re.Match object; span=(24, 43), match='http://blogspot.com'
re.Match object; span=(44, 63), match='https://youtube.com'
re.Match object; span=(64, 84), match='https://www.nasa.gov'

---------------------------------

==========================================

import re

urls = '''
https://www.google.com
http://blogspot.com
https://youtube.com
https://www.nasa.gov
'''

pattern = re.compile(r'https?://(www\.)?(\w+)(\.\w+)')

matches = pattern.finditer(urls)

for match in matches:
print(match.group(0))

---------------------------------

https://www.google.com
http://blogspot.com
https://youtube.com
https://www.nasa.gov

---------------------------------

for match in matches:
print(match.group(1))

---------------------------------

www.
None
None
www.

---------------------------------

for match in matches:
print(match.group(2))


---------------------------------

google
blogspot
youtube
nasa

---------------------------------

for match in matches:
print(match.group(3))

---------------------------------

.com
.com
.com
.gov

---------------------------------

==========================================

import re

urls = '''
https://www.google.com
http://blogspot.com
https://youtube.com
https://www.nasa.gov
'''

pattern = re.compile(r'https?://(www\.)?(\w+)(\.\w+)')

subbed_urls = pattern.sub(r'\2\3', urls)

print(subbed_urls)

---------------------------------

google.com
blogspot.com
youtube.com
nasa.gov

---------------------------------

==========================================


import re

text_to_search = '''
abcdefghijklmnopqurtuvwxyz
ABCDEFGHIJKLMNOPQRSTUVWXYZ
1234567890
Ha HaHa
MetaCharacters (Need to be escaped):
. ^ $ * + ? { } [ ] \ | ( )

linuxerhan.com

321-555-4321
123.555.1234
123*555*1234
800-555-1234
900-555-1234

Mr. Schafer
Mr Smith
Ms Davis
Mrs. Robinson
Mr. T
'''


sentence = 'Start a sentence and then bring it to an end'

pattern = re.compile(r'(Mr|Ms|Mrs)\.?\s[A-Z]\w*')

matches = pattern.findall(text_to_search)


for match in matches:
print(match)

---------------------------------

Mr
Mr
Ms
Mrs
Mr

---------------------------------

pattern = re.compile(r'\d{3}.\d{3}.\d{4}')

---------------------------------

321-555-4321
123.555.1234
123*555*1234
800-555-1234
900-555-1234

---------------------------------

==========================================

import re

text_to_search = '''
abcdefghijklmnopqurtuvwxyz
ABCDEFGHIJKLMNOPQRSTUVWXYZ
1234567890
Ha HaHa
MetaCharacters (Need to be escaped):
. ^ $ * + ? { } [ ] \ | ( )

linuxerhan.com

321-555-4321
123.555.1234
123*555*1234
800-555-1234
900-555-1234

Mr. Schafer
Mr Smith
Ms Davis
Mrs. Robinson
Mr. T
'''


sentence = 'Start a sentence and then bring it to an end'

pattern = re.compile(r'Start')

matches = pattern.match(sentence)


print(matches)

---------------------------------

re.Match object; span=(0, 5), match='Start'

---------------------------------

pattern = re.compile(r'sentence')

---------------------------------

None

---------------------------------

==========================================


import re

text_to_search = '''
abcdefghijklmnopqurtuvwxyz
ABCDEFGHIJKLMNOPQRSTUVWXYZ
1234567890
Ha HaHa
MetaCharacters (Need to be escaped):
. ^ $ * + ? { } [ ] \ | ( )

linuxerhan.com

321-555-4321
123.555.1234
123*555*1234
800-555-1234
900-555-1234

Mr. Schafer
Mr Smith
Ms Davis
Mrs. Robinson
Mr. T
'''


sentence = 'Start a sentence and then bring it to an end'

pattern = re.compile(r'sentence')

matches = pattern.search(sentence)


print(matches)

---------------------------------

re.Match object; span=(8, 16), match='sentence'

---------------------------------

pattern = re.compile(r'dne')

---------------------------------

None

---------------------------------

pattern = re.compile(r'start', re.IGNORECASE)

---------------------------------

re.Match object; span=(0, 5), match='Start'

---------------------------------

pattern = re.compile(r'start', re.I)

---------------------------------

re.Match object; span=(0, 5), match='Start'

---------------------------------


5/10/2020

Python - Real World Example - Parsing Names From a CSV to an HTML List

** Real World Example - Parsing Names From a CSV to an HTML List





==========================================

import csv

html_output = ''
names = []

with open('patrons.csv', 'r') as data_file:
csv_data = csv.reader(data_file)

print(list(csv_data))

---------------------------------

[['FirstName', 'LastName', 'Email', 'Pledge', 'Lifetime', 'Status', 'Country', 'Start'], ['1 + Reward', 'Description I will add your name to the contributors page on my website.\n\t\nYou will also be eligible for Patreon-only rewards. I will occasionally give away books that I have read, and will choose a Patron at random to receive those.', '', '', '', '', '', ''], ['John', 'Doe', 'johndoe@linuxerhan.com', '10.00', '20.00', 'Ok', '', '2017-05-06 21:28:06.183108'], ['Dave', 'Smith', 'davesmith@linuxerhan.com', '5.00', '10.00', 'Ok', '', '2017-05-29 16:13:58.318920'], ['Mary', 'Jacobs', 'maryjacobs@linuxerhan.com', '5.00', '10.00', 'Ok', '', '2017-05-14 07:37:01.074648'], ['Jane', 'Stuart', 'janestuart@linuxerhan.com', '5.00', '25.00', 'Ok', '', '2016-12-30 18:12:13'], ['Tom', 'Wright', 'tomwright@linuxerhan.com', '5.00', '15.00', 'Ok', '', '2017-04-14 04:02:06.658439'], ['Steve', 'Robinson', 'steverobinson@linuxerhan.com', '5.00', '20.00', 'Ok', '', '2017-03-17 02:20:14'], ['Nicole', 'Jacobs', 'nicolejacobs@linuxerhan.com', '5.00', '20.00', 'Ok', '', '2017-03-12 17:07:29'], ['Jane', 'Wright', 'janewright@linuxerhan.com', '5.00', '25.00', '', '', '2017-01-14 17:40:06'], ['Jane', 'Doe', 'janedoe@linuxerhan.com', '2.50', '5.00', 'Ok', '', '2017-05-14 11:20:50.798440'], ['Kurt', 'Wright', 'kurtwright@linuxerhan.com', '2.00', '2.00', 'Ok', '', '2017-06-23 21:12:15.662157'], ['Kurt', 'Robinson', 'kurtrobinson@linuxerhan.com', '2.00', '4.00', 'Ok', '', '2017-05-03 03:18:54.877885'], ['Jane', 'Jenkins', 'janejenkins@linuxerhan.com', '2.00', '8.00', 'Ok', '', '2017-03-23 16:37:47.708634'], ['Neil', 'Robinson', 'neilrobinson@linuxerhan.com', '1.50', '3.00', 'Ok', '', '2017-05-26 19:59:51.013984'], ['Tom', 'Patterson', 'tompatterson@linuxerhan.com', '1.34', '4.02', 'Ok', '', '2017-04-27 01:55:12.313799'], ['Sam', 'Jenkins', 'samjenkins@linuxerhan.com', '1.00', '0.00', 'Ok', '', '2017-07-16 02:34:47.674287'], ['Steve', 'Stuart', 'stevestuart@linuxerhan.com', '1.00', '1.00', 'Ok', '', '2017-06-12 03:32:00.706554'], ['Maggie', 'Patterson', 'maggiepatterson@linuxerhan.com', '1.00', '2.00', 'Ok', '', '2017-05-26 01:23:14.097393'], ['Maggie', 'Stuart', 'maggiestuart@linuxerhan.com', '1.00', '2.00', 'Ok', '', '2017-05-19 23:11:08.624354'], ['Jane', 'Doe', 'janedoe@linuxerhan.com', '1.00', '3.00', 'Ok', '', '2017-04-15 19:40:17.044921'], ['Steve', 'Patterson', 'stevepatterson@linuxerhan.com', '1.00', '3.00', 'Ok', '', '2017-04-09 17:14:23.591656'], ['Dave', 'Smith', 'davesmith@linuxerhan.com', '1.00', '3.00', 'Ok', '', '2017-04-01 18:35:10.731005'], ['Sam', 'Wilks', 'samwilks@linuxerhan.com', '1.00', '4.00', 'Ok', '', '2017-03-01 09:40:56'], ['Kurt', 'Jefferson', 'kurtjefferson@linuxerhan.com', '1.00', '5.00', 'Ok', '', '2017-02-24 08:23:05'], ['Sam', 'Stuart', 'samstuart@linuxerhan.com', '1.00', '5.00', 'Ok', '', '2017-02-12 00:14:31'], ['Jane', 'Stuart', 'janestuart@linuxerhan.com', '1.00', '5.00', 'Ok', '', '2017-02-06 14:52:28'], ['Dave', 'Davis', 'davedavis@linuxerhan.com', '1.00', '0.00', '', '', '2016-11-18 01:37:25'], ['Sam', 'Patterson', 'sampatterson@linuxerhan.com', '1.00', '8.00', 'Ok', '', '2016-11-01 11:27:17'], ['Tom', 'Jefferson', 'tomjefferson@linuxerhan.com', '1.00', '10.00', 'Ok', '', '2016-09-27 09:56:48'], ['Jane', 'Stuart', 'janestuart@linuxerhan.com', '1.00', '7.00', '', '', '2016-08-09 14:42:25'], ['Maggie', 'Jefferson', 'maggiejefferson@linuxerhan.com', '1.00', '12.00', 'Ok', '', '2016-07-26 05:02:16'], ['No Reward', 'Description: (None for No Reward)', '', '', '', '', '', ''], ['Mary', 'Wilks', 'marywilks@linuxerhan.com', '20.00', '60.00', 'Ok', '', '2017-04-21 02:44:43.395224'], ['Neil', 'Patterson', 'neilpatterson@linuxerhan.com', '10.00', '80.00', 'Ok', '', '2016-11-12 17:49:37'], ['Corey', 'Davis', 'coreydavis@linuxerhan.com', '6.00', '90.00', 'Ok', '', '2016-04-01 15:19:52'], ['Steve', 'Jacobs', 'stevejacobs@linuxerhan.com', '5.00', '21.00', 'Ok', '', '2017-01-04 19:38:44'], ['Jane', 'Jenkins', 'janejenkins@linuxerhan.com', '5.00', '30.00', 'Ok', '', '2017-01-15 17:24:39'], ['John', 'Jacobs', 'johnjacobs@linuxerhan.com', '3.14', '34.54', 'Ok', '', '2016-08-23 16:09:25'], ['Neil', 'Smith', 'neilsmith@linuxerhan.com', '3.00', '24.00', 'Ok', '', '2016-11-28 02:57:48'], ['Corey', 'Wilks', 'coreywilks@linuxerhan.com', '2.00', '8.00', 'Ok', '', '2017-03-26 20:13:08.207869'], ['Corey', 'Smith', 'coreysmith@linuxerhan.com', '1.00', '0.00', 'Ok', '', '2017-07-05 01:50:35.171076'], ['Mary', 'Patterson', 'marypatterson@linuxerhan.com', '1.00', '0.00', 'Ok', '', '2017-07-04 18:05:23.052059'], ['Jane', 'Stuart', 'janestuart@linuxerhan.com', '1.00', '2.00', 'Ok', '', '2017-05-21 19:42:36.098523'], ['Travis', 'Arnold', 'travisarnold@linuxerhan.com', '1.00', '3.00', 'Ok', '', '2017-04-19 08:04:33.428559'], ['John', 'Robinson', 'johnrobinson@linuxerhan.com', '1.00', '4.00', 'Ok', '', '2017-03-30 14:59:33.850333'], ['Travis', 'Arnold', 'travisarnold@linuxerhan.com', '1.00', '6.00', 'Ok', '', '2017-01-28 22:02:57']]

---------------------------------

==========================================

import csv

html_output = ''
names = []

with open('patrons.csv', 'r') as data_file:
csv_data = csv.reader(data_file)

for line in csv_data:
print(line)

---------------------------------

['FirstName', 'LastName', 'Email', 'Pledge', 'Lifetime', 'Status', 'Country', 'Start']
['1 + Reward', 'Description I will add your name to the contributors page on my website.\n\t\nYou will also be eligible for Patreon-only rewards. I will occasionally give away books that I have read, and will choose a Patron at random to receive those.', '', '', '', '', '', '']
['John', 'Doe', 'johndoe@linuxerhan.com', '10.00', '20.00', 'Ok', '', '2017-05-06 21:28:06.183108']
['Dave', 'Smith', 'davesmith@linuxerhan.com', '5.00', '10.00', 'Ok', '', '2017-05-29 16:13:58.318920']
['Mary', 'Jacobs', 'maryjacobs@linuxerhan.com', '5.00', '10.00', 'Ok', '', '2017-05-14 07:37:01.074648']
['Jane', 'Stuart', 'janestuart@linuxerhan.com', '5.00', '25.00', 'Ok', '', '2016-12-30 18:12:13']
['Tom', 'Wright', 'tomwright@linuxerhan.com', '5.00', '15.00', 'Ok', '', '2017-04-14 04:02:06.658439']
['Steve', 'Robinson', 'steverobinson@linuxerhan.com', '5.00', '20.00', 'Ok', '', '2017-03-17 02:20:14']
['Nicole', 'Jacobs', 'nicolejacobs@linuxerhan.com', '5.00', '20.00', 'Ok', '', '2017-03-12 17:07:29']
['Jane', 'Wright', 'janewright@linuxerhan.com', '5.00', '25.00', '', '', '2017-01-14 17:40:06']
['Jane', 'Doe', 'janedoe@linuxerhan.com', '2.50', '5.00', 'Ok', '', '2017-05-14 11:20:50.798440']
['Kurt', 'Wright', 'kurtwright@linuxerhan.com', '2.00', '2.00', 'Ok', '', '2017-06-23 21:12:15.662157']
['Kurt', 'Robinson', 'kurtrobinson@linuxerhan.com', '2.00', '4.00', 'Ok', '', '2017-05-03 03:18:54.877885']
['Jane', 'Jenkins', 'janejenkins@linuxerhan.com', '2.00', '8.00', 'Ok', '', '2017-03-23 16:37:47.708634']
['Neil', 'Robinson', 'neilrobinson@linuxerhan.com', '1.50', '3.00', 'Ok', '', '2017-05-26 19:59:51.013984']
['Tom', 'Patterson', 'tompatterson@linuxerhan.com', '1.34', '4.02', 'Ok', '', '2017-04-27 01:55:12.313799']
['Sam', 'Jenkins', 'samjenkins@linuxerhan.com', '1.00', '0.00', 'Ok', '', '2017-07-16 02:34:47.674287']
['Steve', 'Stuart', 'stevestuart@linuxerhan.com', '1.00', '1.00', 'Ok', '', '2017-06-12 03:32:00.706554']
['Maggie', 'Patterson', 'maggiepatterson@linuxerhan.com', '1.00', '2.00', 'Ok', '', '2017-05-26 01:23:14.097393']
['Maggie', 'Stuart', 'maggiestuart@linuxerhan.com', '1.00', '2.00', 'Ok', '', '2017-05-19 23:11:08.624354']
['Jane', 'Doe', 'janedoe@linuxerhan.com', '1.00', '3.00', 'Ok', '', '2017-04-15 19:40:17.044921']
['Steve', 'Patterson', 'stevepatterson@linuxerhan.com', '1.00', '3.00', 'Ok', '', '2017-04-09 17:14:23.591656']
['Dave', 'Smith', 'davesmith@linuxerhan.com', '1.00', '3.00', 'Ok', '', '2017-04-01 18:35:10.731005']
['Sam', 'Wilks', 'samwilks@linuxerhan.com', '1.00', '4.00', 'Ok', '', '2017-03-01 09:40:56']
['Kurt', 'Jefferson', 'kurtjefferson@linuxerhan.com', '1.00', '5.00', 'Ok', '', '2017-02-24 08:23:05']
['Sam', 'Stuart', 'samstuart@linuxerhan.com', '1.00', '5.00', 'Ok', '', '2017-02-12 00:14:31']
['Jane', 'Stuart', 'janestuart@linuxerhan.com', '1.00', '5.00', 'Ok', '', '2017-02-06 14:52:28']
['Dave', 'Davis', 'davedavis@linuxerhan.com', '1.00', '0.00', '', '', '2016-11-18 01:37:25']
['Sam', 'Patterson', 'sampatterson@linuxerhan.com', '1.00', '8.00', 'Ok', '', '2016-11-01 11:27:17']
['Tom', 'Jefferson', 'tomjefferson@linuxerhan.com', '1.00', '10.00', 'Ok', '', '2016-09-27 09:56:48']
['Jane', 'Stuart', 'janestuart@linuxerhan.com', '1.00', '7.00', '', '', '2016-08-09 14:42:25']
['Maggie', 'Jefferson', 'maggiejefferson@linuxerhan.com', '1.00', '12.00', 'Ok', '', '2016-07-26 05:02:16']
['No Reward', 'Description: (None for No Reward)', '', '', '', '', '', '']
['Mary', 'Wilks', 'marywilks@linuxerhan.com', '20.00', '60.00', 'Ok', '', '2017-04-21 02:44:43.395224']
['Neil', 'Patterson', 'neilpatterson@linuxerhan.com', '10.00', '80.00', 'Ok', '', '2016-11-12 17:49:37']
['Corey', 'Davis', 'coreydavis@linuxerhan.com', '6.00', '90.00', 'Ok', '', '2016-04-01 15:19:52']
['Steve', 'Jacobs', 'stevejacobs@linuxerhan.com', '5.00', '21.00', 'Ok', '', '2017-01-04 19:38:44']
['Jane', 'Jenkins', 'janejenkins@linuxerhan.com', '5.00', '30.00', 'Ok', '', '2017-01-15 17:24:39']
['John', 'Jacobs', 'johnjacobs@linuxerhan.com', '3.14', '34.54', 'Ok', '', '2016-08-23 16:09:25']
['Neil', 'Smith', 'neilsmith@linuxerhan.com', '3.00', '24.00', 'Ok', '', '2016-11-28 02:57:48']
['Corey', 'Wilks', 'coreywilks@linuxerhan.com', '2.00', '8.00', 'Ok', '', '2017-03-26 20:13:08.207869']
['Corey', 'Smith', 'coreysmith@linuxerhan.com', '1.00', '0.00', 'Ok', '', '2017-07-05 01:50:35.171076']
['Mary', 'Patterson', 'marypatterson@linuxerhan.com', '1.00', '0.00', 'Ok', '', '2017-07-04 18:05:23.052059']
['Jane', 'Stuart', 'janestuart@linuxerhan.com', '1.00', '2.00', 'Ok', '', '2017-05-21 19:42:36.098523']
['Travis', 'Arnold', 'travisarnold@linuxerhan.com', '1.00', '3.00', 'Ok', '', '2017-04-19 08:04:33.428559']
['John', 'Robinson', 'johnrobinson@linuxerhan.com', '1.00', '4.00', 'Ok', '', '2017-03-30 14:59:33.850333']
['Travis', 'Arnold', 'travisarnold@linuxerhan.com', '1.00', '6.00', 'Ok', '', '2017-01-28 22:02:57']

---------------------------------

==========================================

import csv

html_output = ''
names = []

with open('patrons.csv', 'r') as data_file:
csv_data = csv.reader(data_file)

# We don't want headers or first line of bad data
next(csv_data)
next(csv_data)

for line in csv_data:
print(line)

---------------------------------

['John', 'Doe', 'johndoe@linuxerhan.com', '10.00', '20.00', 'Ok', '', '2017-05-06 21:28:06.183108']
['Dave', 'Smith', 'davesmith@linuxerhan.com', '5.00', '10.00', 'Ok', '', '2017-05-29 16:13:58.318920']
['Mary', 'Jacobs', 'maryjacobs@linuxerhan.com', '5.00', '10.00', 'Ok', '', '2017-05-14 07:37:01.074648']
['Jane', 'Stuart', 'janestuart@linuxerhan.com', '5.00', '25.00', 'Ok', '', '2016-12-30 18:12:13']
['Tom', 'Wright', 'tomwright@linuxerhan.com', '5.00', '15.00', 'Ok', '', '2017-04-14 04:02:06.658439']
['Steve', 'Robinson', 'steverobinson@linuxerhan.com', '5.00', '20.00', 'Ok', '', '2017-03-17 02:20:14']
['Nicole', 'Jacobs', 'nicolejacobs@linuxerhan.com', '5.00', '20.00', 'Ok', '', '2017-03-12 17:07:29']
['Jane', 'Wright', 'janewright@linuxerhan.com', '5.00', '25.00', '', '', '2017-01-14 17:40:06']
['Jane', 'Doe', 'janedoe@linuxerhan.com', '2.50', '5.00', 'Ok', '', '2017-05-14 11:20:50.798440']
['Kurt', 'Wright', 'kurtwright@linuxerhan.com', '2.00', '2.00', 'Ok', '', '2017-06-23 21:12:15.662157']
['Kurt', 'Robinson', 'kurtrobinson@linuxerhan.com', '2.00', '4.00', 'Ok', '', '2017-05-03 03:18:54.877885']
['Jane', 'Jenkins', 'janejenkins@linuxerhan.com', '2.00', '8.00', 'Ok', '', '2017-03-23 16:37:47.708634']
['Neil', 'Robinson', 'neilrobinson@linuxerhan.com', '1.50', '3.00', 'Ok', '', '2017-05-26 19:59:51.013984']
['Tom', 'Patterson', 'tompatterson@linuxerhan.com', '1.34', '4.02', 'Ok', '', '2017-04-27 01:55:12.313799']
['Sam', 'Jenkins', 'samjenkins@linuxerhan.com', '1.00', '0.00', 'Ok', '', '2017-07-16 02:34:47.674287']
['Steve', 'Stuart', 'stevestuart@linuxerhan.com', '1.00', '1.00', 'Ok', '', '2017-06-12 03:32:00.706554']
['Maggie', 'Patterson', 'maggiepatterson@linuxerhan.com', '1.00', '2.00', 'Ok', '', '2017-05-26 01:23:14.097393']
['Maggie', 'Stuart', 'maggiestuart@linuxerhan.com', '1.00', '2.00', 'Ok', '', '2017-05-19 23:11:08.624354']
['Jane', 'Doe', 'janedoe@linuxerhan.com', '1.00', '3.00', 'Ok', '', '2017-04-15 19:40:17.044921']
['Steve', 'Patterson', 'stevepatterson@linuxerhan.com', '1.00', '3.00', 'Ok', '', '2017-04-09 17:14:23.591656']
['Dave', 'Smith', 'davesmith@linuxerhan.com', '1.00', '3.00', 'Ok', '', '2017-04-01 18:35:10.731005']
['Sam', 'Wilks', 'samwilks@linuxerhan.com', '1.00', '4.00', 'Ok', '', '2017-03-01 09:40:56']
['Kurt', 'Jefferson', 'kurtjefferson@linuxerhan.com', '1.00', '5.00', 'Ok', '', '2017-02-24 08:23:05']
['Sam', 'Stuart', 'samstuart@linuxerhan.com', '1.00', '5.00', 'Ok', '', '2017-02-12 00:14:31']
['Jane', 'Stuart', 'janestuart@linuxerhan.com', '1.00', '5.00', 'Ok', '', '2017-02-06 14:52:28']
['Dave', 'Davis', 'davedavis@linuxerhan.com', '1.00', '0.00', '', '', '2016-11-18 01:37:25']
['Sam', 'Patterson', 'sampatterson@linuxerhan.com', '1.00', '8.00', 'Ok', '', '2016-11-01 11:27:17']
['Tom', 'Jefferson', 'tomjefferson@linuxerhan.com', '1.00', '10.00', 'Ok', '', '2016-09-27 09:56:48']
['Jane', 'Stuart', 'janestuart@linuxerhan.com', '1.00', '7.00', '', '', '2016-08-09 14:42:25']
['Maggie', 'Jefferson', 'maggiejefferson@linuxerhan.com', '1.00', '12.00', 'Ok', '', '2016-07-26 05:02:16']
['No Reward', 'Description: (None for No Reward)', '', '', '', '', '', '']
['Mary', 'Wilks', 'marywilks@linuxerhan.com', '20.00', '60.00', 'Ok', '', '2017-04-21 02:44:43.395224']
['Neil', 'Patterson', 'neilpatterson@linuxerhan.com', '10.00', '80.00', 'Ok', '', '2016-11-12 17:49:37']
['Corey', 'Davis', 'coreydavis@linuxerhan.com', '6.00', '90.00', 'Ok', '', '2016-04-01 15:19:52']
['Steve', 'Jacobs', 'stevejacobs@linuxerhan.com', '5.00', '21.00', 'Ok', '', '2017-01-04 19:38:44']
['Jane', 'Jenkins', 'janejenkins@linuxerhan.com', '5.00', '30.00', 'Ok', '', '2017-01-15 17:24:39']
['John', 'Jacobs', 'johnjacobs@linuxerhan.com', '3.14', '34.54', 'Ok', '', '2016-08-23 16:09:25']
['Neil', 'Smith', 'neilsmith@linuxerhan.com', '3.00', '24.00', 'Ok', '', '2016-11-28 02:57:48']
['Corey', 'Wilks', 'coreywilks@linuxerhan.com', '2.00', '8.00', 'Ok', '', '2017-03-26 20:13:08.207869']
['Corey', 'Smith', 'coreysmith@linuxerhan.com', '1.00', '0.00', 'Ok', '', '2017-07-05 01:50:35.171076']
['Mary', 'Patterson', 'marypatterson@linuxerhan.com', '1.00', '0.00', 'Ok', '', '2017-07-04 18:05:23.052059']
['Jane', 'Stuart', 'janestuart@linuxerhan.com', '1.00', '2.00', 'Ok', '', '2017-05-21 19:42:36.098523']
['Travis', 'Arnold', 'travisarnold@linuxerhan.com', '1.00', '3.00', 'Ok', '', '2017-04-19 08:04:33.428559']
['John', 'Robinson', 'johnrobinson@linuxerhan.com', '1.00', '4.00', 'Ok', '', '2017-03-30 14:59:33.850333']
['Travis', 'Arnold', 'travisarnold@linuxerhan.com', '1.00', '6.00', 'Ok', '', '2017-01-28 22:02:57']

---------------------------------

==========================================

import csv

html_output = ''
names = []

with open('patrons.csv', 'r') as data_file:
csv_data = csv.reader(data_file)

# We don't want headers or first line of bad data
next(csv_data)
next(csv_data)

for line in csv_data:
names.append(f"{line[0]} {line[1]}")

for name in names:
print(name)

---------------------------------

John Doe
Dave Smith
Mary Jacobs
Jane Stuart
Tom Wright
Steve Robinson
Nicole Jacobs
Jane Wright
Jane Doe
Kurt Wright
Kurt Robinson
Jane Jenkins
Neil Robinson
Tom Patterson
Sam Jenkins
Steve Stuart
Maggie Patterson
Maggie Stuart
Jane Doe
Steve Patterson
Dave Smith
Sam Wilks
Kurt Jefferson
Sam Stuart
Jane Stuart
Dave Davis
Sam Patterson
Tom Jefferson
Jane Stuart
Maggie Jefferson
No Reward Description: (None for No Reward)
Mary Wilks
Neil Patterson
Corey Davis
Steve Jacobs
Jane Jenkins
John Jacobs
Neil Smith
Corey Wilks
Corey Smith
Mary Patterson
Jane Stuart
Travis Arnold
John Robinson
Travis Arnold

---------------------------------

==========================================

import csv

html_output = ''
names = []

with open('patrons.csv', 'r') as data_file:
csv_data = csv.reader(data_file)

# We don't want headers or first line of bad data
next(csv_data)
next(csv_data)

for line in csv_data:
if line[0] == 'No Reward':
break
names.append(f"{line[0]} {line[1]}")

for name in names:
print(name)

---------------------------------

John Doe
Dave Smith
Mary Jacobs
Jane Stuart
Tom Wright
Steve Robinson
Nicole Jacobs
Jane Wright
Jane Doe
Kurt Wright
Kurt Robinson
Jane Jenkins
Neil Robinson
Tom Patterson
Sam Jenkins
Steve Stuart
Maggie Patterson
Maggie Stuart
Jane Doe
Steve Patterson
Dave Smith
Sam Wilks
Kurt Jefferson
Sam Stuart
Jane Stuart
Dave Davis
Sam Patterson
Tom Jefferson
Jane Stuart
Maggie Jefferson

---------------------------------



==========================================




---------------------------------




==========================================


import csv

html_output = ''
names = []

with open('patrons.csv', 'r') as data_file:
csv_data = csv.DictReader(data_file)

for item in csv_data:
print(item)

---------------------------------

{'FirstName': '1 + Reward', 'LastName': 'Description I will add your name to the contributors page on my website.\n\t\nYou will also be eligible for Patreon-only rewards. I will occasionally give away books that I have read, and will choose a Patron at random to receive those.', 'Email': '', 'Pledge': '', 'Lifetime': '', 'Status': '', 'Country': '', 'Start': ''}
{'FirstName': 'John', 'LastName': 'Doe', 'Email': 'johndoe@linuxerhan.com', 'Pledge': '10.00', 'Lifetime': '20.00', 'Status': 'Ok', 'Country': '', 'Start': '2017-05-06 21:28:06.183108'}
{'FirstName': 'Dave', 'LastName': 'Smith', 'Email': 'davesmith@linuxerhan.com', 'Pledge': '5.00', 'Lifetime': '10.00', 'Status': 'Ok', 'Country': '', 'Start': '2017-05-29 16:13:58.318920'}
{'FirstName': 'Mary', 'LastName': 'Jacobs', 'Email': 'maryjacobs@linuxerhan.com', 'Pledge': '5.00', 'Lifetime': '10.00', 'Status': 'Ok', 'Country': '', 'Start': '2017-05-14 07:37:01.074648'}
{'FirstName': 'Jane', 'LastName': 'Stuart', 'Email': 'janestuart@linuxerhan.com', 'Pledge': '5.00', 'Lifetime': '25.00', 'Status': 'Ok', 'Country': '', 'Start': '2016-12-30 18:12:13'}
{'FirstName': 'Tom', 'LastName': 'Wright', 'Email': 'tomwright@linuxerhan.com', 'Pledge': '5.00', 'Lifetime': '15.00', 'Status': 'Ok', 'Country': '', 'Start': '2017-04-14 04:02:06.658439'}
{'FirstName': 'Steve', 'LastName': 'Robinson', 'Email': 'steverobinson@linuxerhan.com', 'Pledge': '5.00', 'Lifetime': '20.00', 'Status': 'Ok', 'Country': '', 'Start': '2017-03-17 02:20:14'}
{'FirstName': 'Nicole', 'LastName': 'Jacobs', 'Email': 'nicolejacobs@linuxerhan.com', 'Pledge': '5.00', 'Lifetime': '20.00', 'Status': 'Ok', 'Country': '', 'Start': '2017-03-12 17:07:29'}
{'FirstName': 'Jane', 'LastName': 'Wright', 'Email': 'janewright@linuxerhan.com', 'Pledge': '5.00', 'Lifetime': '25.00', 'Status': '', 'Country': '', 'Start': '2017-01-14 17:40:06'}
{'FirstName': 'Jane', 'LastName': 'Doe', 'Email': 'janedoe@linuxerhan.com', 'Pledge': '2.50', 'Lifetime': '5.00', 'Status': 'Ok', 'Country': '', 'Start': '2017-05-14 11:20:50.798440'}
{'FirstName': 'Kurt', 'LastName': 'Wright', 'Email': 'kurtwright@linuxerhan.com', 'Pledge': '2.00', 'Lifetime': '2.00', 'Status': 'Ok', 'Country': '', 'Start': '2017-06-23 21:12:15.662157'}
{'FirstName': 'Kurt', 'LastName': 'Robinson', 'Email': 'kurtrobinson@linuxerhan.com', 'Pledge': '2.00', 'Lifetime': '4.00', 'Status': 'Ok', 'Country': '', 'Start': '2017-05-03 03:18:54.877885'}
{'FirstName': 'Jane', 'LastName': 'Jenkins', 'Email': 'janejenkins@linuxerhan.com', 'Pledge': '2.00', 'Lifetime': '8.00', 'Status': 'Ok', 'Country': '', 'Start': '2017-03-23 16:37:47.708634'}
{'FirstName': 'Neil', 'LastName': 'Robinson', 'Email': 'neilrobinson@linuxerhan.com', 'Pledge': '1.50', 'Lifetime': '3.00', 'Status': 'Ok', 'Country': '', 'Start': '2017-05-26 19:59:51.013984'}
{'FirstName': 'Tom', 'LastName': 'Patterson', 'Email': 'tompatterson@linuxerhan.com', 'Pledge': '1.34', 'Lifetime': '4.02', 'Status': 'Ok', 'Country': '', 'Start': '2017-04-27 01:55:12.313799'}
{'FirstName': 'Sam', 'LastName': 'Jenkins', 'Email': 'samjenkins@linuxerhan.com', 'Pledge': '1.00', 'Lifetime': '0.00', 'Status': 'Ok', 'Country': '', 'Start': '2017-07-16 02:34:47.674287'}
{'FirstName': 'Steve', 'LastName': 'Stuart', 'Email': 'stevestuart@linuxerhan.com', 'Pledge': '1.00', 'Lifetime': '1.00', 'Status': 'Ok', 'Country': '', 'Start': '2017-06-12 03:32:00.706554'}
{'FirstName': 'Maggie', 'LastName': 'Patterson', 'Email': 'maggiepatterson@linuxerhan.com', 'Pledge': '1.00', 'Lifetime': '2.00', 'Status': 'Ok', 'Country': '', 'Start': '2017-05-26 01:23:14.097393'}
{'FirstName': 'Maggie', 'LastName': 'Stuart', 'Email': 'maggiestuart@linuxerhan.com', 'Pledge': '1.00', 'Lifetime': '2.00', 'Status': 'Ok', 'Country': '', 'Start': '2017-05-19 23:11:08.624354'}
{'FirstName': 'Jane', 'LastName': 'Doe', 'Email': 'janedoe@linuxerhan.com', 'Pledge': '1.00', 'Lifetime': '3.00', 'Status': 'Ok', 'Country': '', 'Start': '2017-04-15 19:40:17.044921'}
{'FirstName': 'Steve', 'LastName': 'Patterson', 'Email': 'stevepatterson@linuxerhan.com', 'Pledge': '1.00', 'Lifetime': '3.00', 'Status': 'Ok', 'Country': '', 'Start': '2017-04-09 17:14:23.591656'}
{'FirstName': 'Dave', 'LastName': 'Smith', 'Email': 'davesmith@linuxerhan.com', 'Pledge': '1.00', 'Lifetime': '3.00', 'Status': 'Ok', 'Country': '', 'Start': '2017-04-01 18:35:10.731005'}
{'FirstName': 'Sam', 'LastName': 'Wilks', 'Email': 'samwilks@linuxerhan.com', 'Pledge': '1.00', 'Lifetime': '4.00', 'Status': 'Ok', 'Country': '', 'Start': '2017-03-01 09:40:56'}
{'FirstName': 'Kurt', 'LastName': 'Jefferson', 'Email': 'kurtjefferson@linuxerhan.com', 'Pledge': '1.00', 'Lifetime': '5.00', 'Status': 'Ok', 'Country': '', 'Start': '2017-02-24 08:23:05'}
{'FirstName': 'Sam', 'LastName': 'Stuart', 'Email': 'samstuart@linuxerhan.com', 'Pledge': '1.00', 'Lifetime': '5.00', 'Status': 'Ok', 'Country': '', 'Start': '2017-02-12 00:14:31'}
{'FirstName': 'Jane', 'LastName': 'Stuart', 'Email': 'janestuart@linuxerhan.com', 'Pledge': '1.00', 'Lifetime': '5.00', 'Status': 'Ok', 'Country': '', 'Start': '2017-02-06 14:52:28'}
{'FirstName': 'Dave', 'LastName': 'Davis', 'Email': 'davedavis@linuxerhan.com', 'Pledge': '1.00', 'Lifetime': '0.00', 'Status': '', 'Country': '', 'Start': '2016-11-18 01:37:25'}
{'FirstName': 'Sam', 'LastName': 'Patterson', 'Email': 'sampatterson@linuxerhan.com', 'Pledge': '1.00', 'Lifetime': '8.00', 'Status': 'Ok', 'Country': '', 'Start': '2016-11-01 11:27:17'}
{'FirstName': 'Tom', 'LastName': 'Jefferson', 'Email': 'tomjefferson@linuxerhan.com', 'Pledge': '1.00', 'Lifetime': '10.00', 'Status': 'Ok', 'Country': '', 'Start': '2016-09-27 09:56:48'}
{'FirstName': 'Jane', 'LastName': 'Stuart', 'Email': 'janestuart@linuxerhan.com', 'Pledge': '1.00', 'Lifetime': '7.00', 'Status': '', 'Country': '', 'Start': '2016-08-09 14:42:25'}
{'FirstName': 'Maggie', 'LastName': 'Jefferson', 'Email': 'maggiejefferson@linuxerhan.com', 'Pledge': '1.00', 'Lifetime': '12.00', 'Status': 'Ok', 'Country': '', 'Start': '2016-07-26 05:02:16'}
{'FirstName': 'No Reward', 'LastName': 'Description: (None for No Reward)', 'Email': '', 'Pledge': '', 'Lifetime': '', 'Status': '', 'Country': '', 'Start': ''}
{'FirstName': 'Mary', 'LastName': 'Wilks', 'Email': 'marywilks@linuxerhan.com', 'Pledge': '20.00', 'Lifetime': '60.00', 'Status': 'Ok', 'Country': '', 'Start': '2017-04-21 02:44:43.395224'}
{'FirstName': 'Neil', 'LastName': 'Patterson', 'Email': 'neilpatterson@linuxerhan.com', 'Pledge': '10.00', 'Lifetime': '80.00', 'Status': 'Ok', 'Country': '', 'Start': '2016-11-12 17:49:37'}
{'FirstName': 'Corey', 'LastName': 'Davis', 'Email': 'coreydavis@linuxerhan.com', 'Pledge': '6.00', 'Lifetime': '90.00', 'Status': 'Ok', 'Country': '', 'Start': '2016-04-01 15:19:52'}
{'FirstName': 'Steve', 'LastName': 'Jacobs', 'Email': 'stevejacobs@linuxerhan.com', 'Pledge': '5.00', 'Lifetime': '21.00', 'Status': 'Ok', 'Country': '', 'Start': '2017-01-04 19:38:44'}
{'FirstName': 'Jane', 'LastName': 'Jenkins', 'Email': 'janejenkins@linuxerhan.com', 'Pledge': '5.00', 'Lifetime': '30.00', 'Status': 'Ok', 'Country': '', 'Start': '2017-01-15 17:24:39'}
{'FirstName': 'John', 'LastName': 'Jacobs', 'Email': 'johnjacobs@linuxerhan.com', 'Pledge': '3.14', 'Lifetime': '34.54', 'Status': 'Ok', 'Country': '', 'Start': '2016-08-23 16:09:25'}
{'FirstName': 'Neil', 'LastName': 'Smith', 'Email': 'neilsmith@linuxerhan.com', 'Pledge': '3.00', 'Lifetime': '24.00', 'Status': 'Ok', 'Country': '', 'Start': '2016-11-28 02:57:48'}
{'FirstName': 'Corey', 'LastName': 'Wilks', 'Email': 'coreywilks@linuxerhan.com', 'Pledge': '2.00', 'Lifetime': '8.00', 'Status': 'Ok', 'Country': '', 'Start': '2017-03-26 20:13:08.207869'}
{'FirstName': 'Corey', 'LastName': 'Smith', 'Email': 'coreysmith@linuxerhan.com', 'Pledge': '1.00', 'Lifetime': '0.00', 'Status': 'Ok', 'Country': '', 'Start': '2017-07-05 01:50:35.171076'}
{'FirstName': 'Mary', 'LastName': 'Patterson', 'Email': 'marypatterson@linuxerhan.com', 'Pledge': '1.00', 'Lifetime': '0.00', 'Status': 'Ok', 'Country': '', 'Start': '2017-07-04 18:05:23.052059'}
{'FirstName': 'Jane', 'LastName': 'Stuart', 'Email': 'janestuart@linuxerhan.com', 'Pledge': '1.00', 'Lifetime': '2.00', 'Status': 'Ok', 'Country': '', 'Start': '2017-05-21 19:42:36.098523'}
{'FirstName': 'Travis', 'LastName': 'Arnold', 'Email': 'travisarnold@linuxerhan.com', 'Pledge': '1.00', 'Lifetime': '3.00', 'Status': 'Ok', 'Country': '', 'Start': '2017-04-19 08:04:33.428559'}
{'FirstName': 'John', 'LastName': 'Robinson', 'Email': 'johnrobinson@linuxerhan.com', 'Pledge': '1.00', 'Lifetime': '4.00', 'Status': 'Ok', 'Country': '', 'Start': '2017-03-30 14:59:33.850333'}
{'FirstName': 'Travis', 'LastName': 'Arnold', 'Email': 'travisarnold@linuxerhan.com', 'Pledge': '1.00', 'Lifetime': '6.00', 'Status': 'Ok', 'Country': '', 'Start': '2017-01-28 22:02:57'}

---------------------------------

==========================================




---------------------------------



---------------------------------

Python - CSV Module - How to Read, Parse, and Write CSV Files

** CSV Module - How to Read, Parse, and Write CSV Files


==========================================

import csv

with open('names2.csv', 'r') as csv_file:
csv_reader = csv.reader(csv_file)

for line in csv_reader:
print(line)

---------------------------------

['first_name', 'last_name', 'email']
['John', 'Doe', 'john-doe@linuxerhan.com']
['Mary', 'Smith-Robinson', 'maryjacobs@linuxerhan.com']
['Dave', 'Smith', 'davesmith@linuxerhan.com']
['Jane', 'Stuart', 'janestuart@linuxerhan.com']
['Tom', 'Wright', 'tomwright@linuxerhan.com']
['Steve', 'Robinson', 'steverobinson@linuxerhan.com']
['Nicole', 'Jacobs', 'nicolejacobs@linuxerhan.com']
['Jane', 'Wright', 'janewright@linuxerhan.com']
['Jane', 'Doe', 'janedoe@linuxerhan.com']
['Kurt', 'Wright', 'kurtwright@linuxerhan.com']
['Kurt', 'Robinson', 'kurtrobinson@linuxerhan.com']
['Jane', 'Jenkins', 'janejenkins@linuxerhan.com']
['Neil', 'Robinson', 'neilrobinson@linuxerhan.com']
['Tom', 'Patterson', 'tompatterson@linuxerhan.com']
['Sam', 'Jenkins', 'samjenkins@linuxerhan.com']
['Steve', 'Stuart', 'stevestuart@linuxerhan.com']
['Maggie', 'Patterson', 'maggiepatterson@linuxerhan.com']
['Maggie', 'Stuart', 'maggiestuart@linuxerhan.com']
['Jane', 'Doe', 'janedoe@linuxerhan.com']
['Steve', 'Patterson', 'stevepatterson@linuxerhan.com']
['Dave', 'Smith', 'davesmith@linuxerhan.com']
['Sam', 'Wilks', 'samwilks@linuxerhan.com']
['Kurt', 'Jefferson', 'kurtjefferson@linuxerhan.com']
['Sam', 'Stuart', 'samstuart@linuxerhan.com']
['Jane', 'Stuart', 'janestuart@linuxerhan.com']
['Dave', 'Davis', 'davedavis@linuxerhan.com']
['Sam', 'Patterson', 'sampatterson@linuxerhan.com']
['Tom', 'Jefferson', 'tomjefferson@linuxerhan.com']
['Jane', 'Stuart', 'janestuart@linuxerhan.com']
['Maggie', 'Jefferson', 'maggiejefferson@linuxerhan.com']
['Mary', 'Wilks', 'marywilks@linuxerhan.com']
['Neil', 'Patterson', 'neilpatterson@linuxerhan.com']
['Corey', 'Davis', 'coreydavis@linuxerhan.com']
['Steve', 'Jacobs', 'stevejacobs@linuxerhan.com']
['Jane', 'Jenkins', 'janejenkins@linuxerhan.com']
['John', 'Jacobs', 'johnjacobs@linuxerhan.com']
['Neil', 'Smith', 'neilsmith@linuxerhan.com']
['Corey', 'Wilks', 'coreywilks@linuxerhan.com']
['Corey', 'Smith', 'coreysmith@linuxerhan.com']
['Mary', 'Patterson', 'marypatterson@linuxerhan.com']
['Jane', 'Stuart', 'janestuart@linuxerhan.com']
['Travis', 'Arnold', 'travisarnold@linuxerhan.com']
['John', 'Robinson', 'johnrobinson@linuxerhan.com']
['Travis', 'Arnold', 'travisarnold@linuxerhan.com']

---------------------------------

==========================================

import csv

with open('names2.csv', 'r') as csv_file:
csv_reader = csv.reader(csv_file)

for line in csv_reader:
print(line[2])

---------------------------------

email
john-doe@linuxerhan.com
maryjacobs@linuxerhan.com
davesmith@linuxerhan.com
janestuart@linuxerhan.com
tomwright@linuxerhan.com
steverobinson@linuxerhan.com
nicolejacobs@linuxerhan.com
janewright@linuxerhan.com
janedoe@linuxerhan.com
kurtwright@linuxerhan.com
kurtrobinson@linuxerhan.com
janejenkins@linuxerhan.com
neilrobinson@linuxerhan.com
tompatterson@linuxerhan.com
samjenkins@linuxerhan.com
stevestuart@linuxerhan.com
maggiepatterson@linuxerhan.com
maggiestuart@linuxerhan.com
janedoe@linuxerhan.com
stevepatterson@linuxerhan.com
davesmith@linuxerhan.com
samwilks@linuxerhan.com
kurtjefferson@linuxerhan.com
samstuart@linuxerhan.com
janestuart@linuxerhan.com
davedavis@linuxerhan.com
sampatterson@linuxerhan.com
tomjefferson@linuxerhan.com
janestuart@linuxerhan.com
maggiejefferson@linuxerhan.com
marywilks@linuxerhan.com
neilpatterson@linuxerhan.com
coreydavis@linuxerhan.com
stevejacobs@linuxerhan.com
janejenkins@linuxerhan.com
johnjacobs@linuxerhan.com
neilsmith@linuxerhan.com
coreywilks@linuxerhan.com
coreysmith@linuxerhan.com
marypatterson@linuxerhan.com
janestuart@linuxerhan.com
travisarnold@linuxerhan.com
johnrobinson@linuxerhan.com
travisarnold@linuxerhan.com

---------------------------------

==========================================

import csv

with open('names2.csv', 'r') as csv_file:
csv_reader = csv.reader(csv_file)

next(csv_reader)

for line in csv_reader:
print(line[2])

---------------------------------

john-doe@linuxerhan.com
maryjacobs@linuxerhan.com
davesmith@linuxerhan.com
janestuart@linuxerhan.com
tomwright@linuxerhan.com
steverobinson@linuxerhan.com
nicolejacobs@linuxerhan.com
janewright@linuxerhan.com
janedoe@linuxerhan.com
kurtwright@linuxerhan.com
kurtrobinson@linuxerhan.com
janejenkins@linuxerhan.com
neilrobinson@linuxerhan.com
tompatterson@linuxerhan.com
samjenkins@linuxerhan.com
stevestuart@linuxerhan.com
maggiepatterson@linuxerhan.com
maggiestuart@linuxerhan.com
janedoe@linuxerhan.com
stevepatterson@linuxerhan.com
davesmith@linuxerhan.com
samwilks@linuxerhan.com
kurtjefferson@linuxerhan.com
samstuart@linuxerhan.com
janestuart@linuxerhan.com
davedavis@linuxerhan.com
sampatterson@linuxerhan.com
tomjefferson@linuxerhan.com
janestuart@linuxerhan.com
maggiejefferson@linuxerhan.com
marywilks@linuxerhan.com
neilpatterson@linuxerhan.com
coreydavis@linuxerhan.com
stevejacobs@linuxerhan.com
janejenkins@linuxerhan.com
johnjacobs@linuxerhan.com
neilsmith@linuxerhan.com
coreywilks@linuxerhan.com
coreysmith@linuxerhan.com
marypatterson@linuxerhan.com
janestuart@linuxerhan.com
travisarnold@linuxerhan.com
johnrobinson@linuxerhan.com
travisarnold@linuxerhan.com

---------------------------------

==========================================

import csv

with open('names2.csv', 'r') as csv_file:
csv_reader = csv.reader(csv_file)

with open('new_names2.csv', 'w') as new_file:
csv_writer = csv.writer(new_file, delimiter = '-')

for line in csv_reader:
csv_writer.writerow(line)

---------------------------------

first_name-last_name-email

John-Doe-"john-doe@linuxerhan.com"

Mary-"Smith-Robinson"-maryjacobs@linuxerhan.com

Dave-Smith-davesmith@linuxerhan.com

Jane-Stuart-janestuart@linuxerhan.com

Tom-Wright-tomwright@linuxerhan.com

Steve-Robinson-steverobinson@linuxerhan.com

Nicole-Jacobs-nicolejacobs@linuxerhan.com

Jane-Wright-janewright@linuxerhan.com

Jane-Doe-janedoe@linuxerhan.com

Kurt-Wright-kurtwright@linuxerhan.com

Kurt-Robinson-kurtrobinson@linuxerhan.com

Jane-Jenkins-janejenkins@linuxerhan.com

Neil-Robinson-neilrobinson@linuxerhan.com

Tom-Patterson-tompatterson@linuxerhan.com

Sam-Jenkins-samjenkins@linuxerhan.com

Steve-Stuart-stevestuart@linuxerhan.com

Maggie-Patterson-maggiepatterson@linuxerhan.com

Maggie-Stuart-maggiestuart@linuxerhan.com

Jane-Doe-janedoe@linuxerhan.com

Steve-Patterson-stevepatterson@linuxerhan.com

Dave-Smith-davesmith@linuxerhan.com

Sam-Wilks-samwilks@linuxerhan.com

Kurt-Jefferson-kurtjefferson@linuxerhan.com

Sam-Stuart-samstuart@linuxerhan.com

Jane-Stuart-janestuart@linuxerhan.com

Dave-Davis-davedavis@linuxerhan.com

Sam-Patterson-sampatterson@linuxerhan.com

Tom-Jefferson-tomjefferson@linuxerhan.com

Jane-Stuart-janestuart@linuxerhan.com

Maggie-Jefferson-maggiejefferson@linuxerhan.com

Mary-Wilks-marywilks@linuxerhan.com

Neil-Patterson-neilpatterson@linuxerhan.com

Corey-Davis-coreydavis@linuxerhan.com

Steve-Jacobs-stevejacobs@linuxerhan.com

Jane-Jenkins-janejenkins@linuxerhan.com

John-Jacobs-johnjacobs@linuxerhan.com

Neil-Smith-neilsmith@linuxerhan.com

Corey-Wilks-coreywilks@linuxerhan.com

Corey-Smith-coreysmith@linuxerhan.com

Mary-Patterson-marypatterson@linuxerhan.com

Jane-Stuart-janestuart@linuxerhan.com

Travis-Arnold-travisarnold@linuxerhan.com

John-Robinson-johnrobinson@linuxerhan.com

Travis-Arnold-travisarnold@linuxerhan.com

---------------------------------

==========================================

import csv

with open('names2.csv', 'r') as csv_file:
csv_reader = csv.reader(csv_file)

with open('new_names2.csv', 'w') as new_file:
csv_writer = csv.writer(new_file, delimiter = '\t')

for line in csv_reader:
csv_writer.writerow(line)

---------------------------------

first_name last_name email

John Doe john-doe@linuxerhan.com

Mary Smith-Robinson maryjacobs@linuxerhan.com

Dave Smith davesmith@linuxerhan.com

Jane Stuart janestuart@linuxerhan.com

Tom Wright tomwright@linuxerhan.com

Steve Robinson steverobinson@linuxerhan.com

Nicole Jacobs nicolejacobs@linuxerhan.com

Jane Wright janewright@linuxerhan.com

Jane Doe janedoe@linuxerhan.com

Kurt Wright kurtwright@linuxerhan.com

Kurt Robinson kurtrobinson@linuxerhan.com

Jane Jenkins janejenkins@linuxerhan.com

Neil Robinson neilrobinson@linuxerhan.com

Tom Patterson tompatterson@linuxerhan.com

Sam Jenkins samjenkins@linuxerhan.com

Steve Stuart stevestuart@linuxerhan.com

Maggie Patterson maggiepatterson@linuxerhan.com

Maggie Stuart maggiestuart@linuxerhan.com

Jane Doe janedoe@linuxerhan.com

Steve Patterson stevepatterson@linuxerhan.com

Dave Smith davesmith@linuxerhan.com

Sam Wilks samwilks@linuxerhan.com

Kurt Jefferson kurtjefferson@linuxerhan.com

Sam Stuart samstuart@linuxerhan.com

Jane Stuart janestuart@linuxerhan.com

Dave Davis davedavis@linuxerhan.com

Sam Patterson sampatterson@linuxerhan.com

Tom Jefferson tomjefferson@linuxerhan.com

Jane Stuart janestuart@linuxerhan.com

Maggie Jefferson maggiejefferson@linuxerhan.com

Mary Wilks marywilks@linuxerhan.com

Neil Patterson neilpatterson@linuxerhan.com

Corey Davis coreydavis@linuxerhan.com

Steve Jacobs stevejacobs@linuxerhan.com

Jane Jenkins janejenkins@linuxerhan.com

John Jacobs johnjacobs@linuxerhan.com

Neil Smith neilsmith@linuxerhan.com

Corey Wilks coreywilks@linuxerhan.com

Corey Smith coreysmith@linuxerhan.com

Mary Patterson marypatterson@linuxerhan.com

Jane Stuart janestuart@linuxerhan.com

Travis Arnold travisarnold@linuxerhan.com

John Robinson johnrobinson@linuxerhan.com

Travis Arnold travisarnold@linuxerhan.com

---------------------------------

==========================================

import csv

with open('new_names2.csv', 'r') as csv_file:
csv_reader = csv.reader(csv_file)

for line in csv_reader:
print(line)

---------------------------------

['first_name\tlast_name\temail']
['John\tDoe\tjohn-doe@linuxerhan.com']
['Mary\tSmith-Robinson\tmaryjacobs@linuxerhan.com']
['Dave\tSmith\tdavesmith@linuxerhan.com']
['Jane\tStuart\tjanestuart@linuxerhan.com']
['Tom\tWright\ttomwright@linuxerhan.com']
['Steve\tRobinson\tsteverobinson@linuxerhan.com']
['Nicole\tJacobs\tnicolejacobs@linuxerhan.com']
['Jane\tWright\tjanewright@linuxerhan.com']
['Jane\tDoe\tjanedoe@linuxerhan.com']
['Kurt\tWright\tkurtwright@linuxerhan.com']
['Kurt\tRobinson\tkurtrobinson@linuxerhan.com']
['Jane\tJenkins\tjanejenkins@linuxerhan.com']
['Neil\tRobinson\tneilrobinson@linuxerhan.com']
['Tom\tPatterson\ttompatterson@linuxerhan.com']
['Sam\tJenkins\tsamjenkins@linuxerhan.com']
['Steve\tStuart\tstevestuart@linuxerhan.com']
['Maggie\tPatterson\tmaggiepatterson@linuxerhan.com']
['Maggie\tStuart\tmaggiestuart@linuxerhan.com']
['Jane\tDoe\tjanedoe@linuxerhan.com']
['Steve\tPatterson\tstevepatterson@linuxerhan.com']
['Dave\tSmith\tdavesmith@linuxerhan.com']
['Sam\tWilks\tsamwilks@linuxerhan.com']
['Kurt\tJefferson\tkurtjefferson@linuxerhan.com']
['Sam\tStuart\tsamstuart@linuxerhan.com']
['Jane\tStuart\tjanestuart@linuxerhan.com']
['Dave\tDavis\tdavedavis@linuxerhan.com']
['Sam\tPatterson\tsampatterson@linuxerhan.com']
['Tom\tJefferson\ttomjefferson@linuxerhan.com']
['Jane\tStuart\tjanestuart@linuxerhan.com']
['Maggie\tJefferson\tmaggiejefferson@linuxerhan.com']
['Mary\tWilks\tmarywilks@linuxerhan.com']
['Neil\tPatterson\tneilpatterson@linuxerhan.com']
['Corey\tDavis\tcoreydavis@linuxerhan.com']
['Steve\tJacobs\tstevejacobs@linuxerhan.com']
['Jane\tJenkins\tjanejenkins@linuxerhan.com']
['John\tJacobs\tjohnjacobs@linuxerhan.com']
['Neil\tSmith\tneilsmith@linuxerhan.com']
['Corey\tWilks\tcoreywilks@linuxerhan.com']
['Corey\tSmith\tcoreysmith@linuxerhan.com']
['Mary\tPatterson\tmarypatterson@linuxerhan.com']
['Jane\tStuart\tjanestuart@linuxerhan.com']
['Travis\tArnold\ttravisarnold@linuxerhan.com']
['John\tRobinson\tjohnrobinson@linuxerhan.com']
['Travis\tArnold\ttravisarnold@linuxerhan.com']

---------------------------------

==========================================

import csv

with open('new_names2.csv', 'r') as csv_file:
csv_reader = csv.reader(csv_file, delimiter = '\t')

for line in csv_reader:
print(line)

---------------------------------

['first_name', 'last_name', 'email']
['John', 'Doe', 'john-doe@linuxerhan.com']
['Mary', 'Smith-Robinson', 'maryjacobs@linuxerhan.com']
['Dave', 'Smith', 'davesmith@linuxerhan.com']
['Jane', 'Stuart', 'janestuart@linuxerhan.com']
['Tom', 'Wright', 'tomwright@linuxerhan.com']
['Steve', 'Robinson', 'steverobinson@linuxerhan.com']
['Nicole', 'Jacobs', 'nicolejacobs@linuxerhan.com']
['Jane', 'Wright', 'janewright@linuxerhan.com']
['Jane', 'Doe', 'janedoe@linuxerhan.com']
['Kurt', 'Wright', 'kurtwright@linuxerhan.com']
['Kurt', 'Robinson', 'kurtrobinson@linuxerhan.com']
['Jane', 'Jenkins', 'janejenkins@linuxerhan.com']
['Neil', 'Robinson', 'neilrobinson@linuxerhan.com']
['Tom', 'Patterson', 'tompatterson@linuxerhan.com']
['Sam', 'Jenkins', 'samjenkins@linuxerhan.com']
['Steve', 'Stuart', 'stevestuart@linuxerhan.com']
['Maggie', 'Patterson', 'maggiepatterson@linuxerhan.com']
['Maggie', 'Stuart', 'maggiestuart@linuxerhan.com']
['Jane', 'Doe', 'janedoe@linuxerhan.com']
['Steve', 'Patterson', 'stevepatterson@linuxerhan.com']
['Dave', 'Smith', 'davesmith@linuxerhan.com']
['Sam', 'Wilks', 'samwilks@linuxerhan.com']
['Kurt', 'Jefferson', 'kurtjefferson@linuxerhan.com']
['Sam', 'Stuart', 'samstuart@linuxerhan.com']
['Jane', 'Stuart', 'janestuart@linuxerhan.com']
['Dave', 'Davis', 'davedavis@linuxerhan.com']
['Sam', 'Patterson', 'sampatterson@linuxerhan.com']
['Tom', 'Jefferson', 'tomjefferson@linuxerhan.com']
['Jane', 'Stuart', 'janestuart@linuxerhan.com']
['Maggie', 'Jefferson', 'maggiejefferson@linuxerhan.com']
['Mary', 'Wilks', 'marywilks@linuxerhan.com']
['Neil', 'Patterson', 'neilpatterson@linuxerhan.com']
['Corey', 'Davis', 'coreydavis@linuxerhan.com']
['Steve', 'Jacobs', 'stevejacobs@linuxerhan.com']
['Jane', 'Jenkins', 'janejenkins@linuxerhan.com']
['John', 'Jacobs', 'johnjacobs@linuxerhan.com']
['Neil', 'Smith', 'neilsmith@linuxerhan.com']
['Corey', 'Wilks', 'coreywilks@linuxerhan.com']
['Corey', 'Smith', 'coreysmith@linuxerhan.com']
['Mary', 'Patterson', 'marypatterson@linuxerhan.com']
['Jane', 'Stuart', 'janestuart@linuxerhan.com']
['Travis', 'Arnold', 'travisarnold@linuxerhan.com']
['John', 'Robinson', 'johnrobinson@linuxerhan.com']
['Travis', 'Arnold', 'travisarnold@linuxerhan.com']

---------------------------------

==========================================

import csv


with open('names2.csv', 'r') as csv_file:
csv_reader = csv.DictReader(csv_file)

for line in csv_reader:
print(line)

---------------------------------

{'first_name': 'John', 'last_name': 'Doe', 'email': 'john-doe@linuxerhan.com'}
{'first_name': 'Mary', 'last_name': 'Smith-Robinson', 'email': 'maryjacobs@linuxerhan.com'}
{'first_name': 'Dave', 'last_name': 'Smith', 'email': 'davesmith@linuxerhan.com'}
{'first_name': 'Jane', 'last_name': 'Stuart', 'email': 'janestuart@linuxerhan.com'}
{'first_name': 'Tom', 'last_name': 'Wright', 'email': 'tomwright@linuxerhan.com'}
{'first_name': 'Steve', 'last_name': 'Robinson', 'email': 'steverobinson@linuxerhan.com'}
{'first_name': 'Nicole', 'last_name': 'Jacobs', 'email': 'nicolejacobs@linuxerhan.com'}
{'first_name': 'Jane', 'last_name': 'Wright', 'email': 'janewright@linuxerhan.com'}
{'first_name': 'Jane', 'last_name': 'Doe', 'email': 'janedoe@linuxerhan.com'}
{'first_name': 'Kurt', 'last_name': 'Wright', 'email': 'kurtwright@linuxerhan.com'}
{'first_name': 'Kurt', 'last_name': 'Robinson', 'email': 'kurtrobinson@linuxerhan.com'}
{'first_name': 'Jane', 'last_name': 'Jenkins', 'email': 'janejenkins@linuxerhan.com'}
{'first_name': 'Neil', 'last_name': 'Robinson', 'email': 'neilrobinson@linuxerhan.com'}
{'first_name': 'Tom', 'last_name': 'Patterson', 'email': 'tompatterson@linuxerhan.com'}
{'first_name': 'Sam', 'last_name': 'Jenkins', 'email': 'samjenkins@linuxerhan.com'}
{'first_name': 'Steve', 'last_name': 'Stuart', 'email': 'stevestuart@linuxerhan.com'}
{'first_name': 'Maggie', 'last_name': 'Patterson', 'email': 'maggiepatterson@linuxerhan.com'}
{'first_name': 'Maggie', 'last_name': 'Stuart', 'email': 'maggiestuart@linuxerhan.com'}
{'first_name': 'Jane', 'last_name': 'Doe', 'email': 'janedoe@linuxerhan.com'}
{'first_name': 'Steve', 'last_name': 'Patterson', 'email': 'stevepatterson@linuxerhan.com'}
{'first_name': 'Dave', 'last_name': 'Smith', 'email': 'davesmith@linuxerhan.com'}
{'first_name': 'Sam', 'last_name': 'Wilks', 'email': 'samwilks@linuxerhan.com'}
{'first_name': 'Kurt', 'last_name': 'Jefferson', 'email': 'kurtjefferson@linuxerhan.com'}
{'first_name': 'Sam', 'last_name': 'Stuart', 'email': 'samstuart@linuxerhan.com'}
{'first_name': 'Jane', 'last_name': 'Stuart', 'email': 'janestuart@linuxerhan.com'}
{'first_name': 'Dave', 'last_name': 'Davis', 'email': 'davedavis@linuxerhan.com'}
{'first_name': 'Sam', 'last_name': 'Patterson', 'email': 'sampatterson@linuxerhan.com'}
{'first_name': 'Tom', 'last_name': 'Jefferson', 'email': 'tomjefferson@linuxerhan.com'}
{'first_name': 'Jane', 'last_name': 'Stuart', 'email': 'janestuart@linuxerhan.com'}
{'first_name': 'Maggie', 'last_name': 'Jefferson', 'email': 'maggiejefferson@linuxerhan.com'}
{'first_name': 'Mary', 'last_name': 'Wilks', 'email': 'marywilks@linuxerhan.com'}
{'first_name': 'Neil', 'last_name': 'Patterson', 'email': 'neilpatterson@linuxerhan.com'}
{'first_name': 'Corey', 'last_name': 'Davis', 'email': 'coreydavis@linuxerhan.com'}
{'first_name': 'Steve', 'last_name': 'Jacobs', 'email': 'stevejacobs@linuxerhan.com'}
{'first_name': 'Jane', 'last_name': 'Jenkins', 'email': 'janejenkins@linuxerhan.com'}
{'first_name': 'John', 'last_name': 'Jacobs', 'email': 'johnjacobs@linuxerhan.com'}
{'first_name': 'Neil', 'last_name': 'Smith', 'email': 'neilsmith@linuxerhan.com'}
{'first_name': 'Corey', 'last_name': 'Wilks', 'email': 'coreywilks@linuxerhan.com'}
{'first_name': 'Corey', 'last_name': 'Smith', 'email': 'coreysmith@linuxerhan.com'}
{'first_name': 'Mary', 'last_name': 'Patterson', 'email': 'marypatterson@linuxerhan.com'}
{'first_name': 'Jane', 'last_name': 'Stuart', 'email': 'janestuart@linuxerhan.com'}
{'first_name': 'Travis', 'last_name': 'Arnold', 'email': 'travisarnold@linuxerhan.com'}
{'first_name': 'John', 'last_name': 'Robinson', 'email': 'johnrobinson@linuxerhan.com'}
{'first_name': 'Travis', 'last_name': 'Arnold', 'email': 'travisarnold@linuxerhan.com'}

---------------------------------

==========================================

import csv


with open('names2.csv', 'r') as csv_file:
csv_reader = csv.DictReader(csv_file)

for line in csv_reader:
print(line['email'])

---------------------------------

john-doe@linuxerhan.com
maryjacobs@linuxerhan.com
davesmith@linuxerhan.com
janestuart@linuxerhan.com
tomwright@linuxerhan.com
steverobinson@linuxerhan.com
nicolejacobs@linuxerhan.com
janewright@linuxerhan.com
janedoe@linuxerhan.com
kurtwright@linuxerhan.com
kurtrobinson@linuxerhan.com
janejenkins@linuxerhan.com
neilrobinson@linuxerhan.com
tompatterson@linuxerhan.com
samjenkins@linuxerhan.com
stevestuart@linuxerhan.com
maggiepatterson@linuxerhan.com
maggiestuart@linuxerhan.com
janedoe@linuxerhan.com
stevepatterson@linuxerhan.com
davesmith@linuxerhan.com
samwilks@linuxerhan.com
kurtjefferson@linuxerhan.com
samstuart@linuxerhan.com
janestuart@linuxerhan.com
davedavis@linuxerhan.com
sampatterson@linuxerhan.com
tomjefferson@linuxerhan.com
janestuart@linuxerhan.com
maggiejefferson@linuxerhan.com
marywilks@linuxerhan.com
neilpatterson@linuxerhan.com
coreydavis@linuxerhan.com
stevejacobs@linuxerhan.com
janejenkins@linuxerhan.com
johnjacobs@linuxerhan.com
neilsmith@linuxerhan.com
coreywilks@linuxerhan.com
coreysmith@linuxerhan.com
marypatterson@linuxerhan.com
janestuart@linuxerhan.com
travisarnold@linuxerhan.com
johnrobinson@linuxerhan.com
travisarnold@linuxerhan.com

---------------------------------

==========================================

import csv


with open('names2.csv', 'r') as csv_file:
csv_reader = csv.DictReader(csv_file)


with open('new_names2.csv', 'w') as new_file:
fieldnames = ['first_name', 'last_name', 'email']

csv_writer = csv.DictWriter(new_file, fieldnames = fieldnames, delimiter = '\t')

csv_writer.writeheader()

for line in csv_reader:
csv_writer.writerow(line)


---------------------------------

first_name last_name email

John Doe john-doe@linuxerhan.com

Mary Smith-Robinson maryjacobs@linuxerhan.com

Dave Smith davesmith@linuxerhan.com

Jane Stuart janestuart@linuxerhan.com

Tom Wright tomwright@linuxerhan.com

Steve Robinson steverobinson@linuxerhan.com

Nicole Jacobs nicolejacobs@linuxerhan.com

Jane Wright janewright@linuxerhan.com

Jane Doe janedoe@linuxerhan.com

Kurt Wright kurtwright@linuxerhan.com

Kurt Robinson kurtrobinson@linuxerhan.com

Jane Jenkins janejenkins@linuxerhan.com

Neil Robinson neilrobinson@linuxerhan.com

Tom Patterson tompatterson@linuxerhan.com

Sam Jenkins samjenkins@linuxerhan.com

Steve Stuart stevestuart@linuxerhan.com

Maggie Patterson maggiepatterson@linuxerhan.com

Maggie Stuart maggiestuart@linuxerhan.com

Jane Doe janedoe@linuxerhan.com

Steve Patterson stevepatterson@linuxerhan.com

Dave Smith davesmith@linuxerhan.com

Sam Wilks samwilks@linuxerhan.com

Kurt Jefferson kurtjefferson@linuxerhan.com

Sam Stuart samstuart@linuxerhan.com

Jane Stuart janestuart@linuxerhan.com

Dave Davis davedavis@linuxerhan.com

Sam Patterson sampatterson@linuxerhan.com

Tom Jefferson tomjefferson@linuxerhan.com

Jane Stuart janestuart@linuxerhan.com

Maggie Jefferson maggiejefferson@linuxerhan.com

Mary Wilks marywilks@linuxerhan.com

Neil Patterson neilpatterson@linuxerhan.com

Corey Davis coreydavis@linuxerhan.com

Steve Jacobs stevejacobs@linuxerhan.com

Jane Jenkins janejenkins@linuxerhan.com

John Jacobs johnjacobs@linuxerhan.com

Neil Smith neilsmith@linuxerhan.com

Corey Wilks coreywilks@linuxerhan.com

Corey Smith coreysmith@linuxerhan.com

Mary Patterson marypatterson@linuxerhan.com

Jane Stuart janestuart@linuxerhan.com

Travis Arnold travisarnold@linuxerhan.com

John Robinson johnrobinson@linuxerhan.com

Travis Arnold travisarnold@linuxerhan.com

---------------------------------

==========================================

import csv


with open('names2.csv', 'r') as csv_file:
csv_reader = csv.DictReader(csv_file)


with open('new_names2.csv', 'w') as new_file:
fieldnames = ['first_name', 'last_name']

csv_writer = csv.DictWriter(new_file, fieldnames = fieldnames, delimiter = '\t')

csv_writer.writeheader()

for line in csv_reader:
del line['email']
csv_writer.writerow(line)


---------------------------------

first_name last_name

John Doe

Mary Smith-Robinson

Dave Smith

Jane Stuart

Tom Wright

Steve Robinson

Nicole Jacobs

Jane Wright

Jane Doe

Kurt Wright

Kurt Robinson

Jane Jenkins

Neil Robinson

Tom Patterson

Sam Jenkins

Steve Stuart

Maggie Patterson

Maggie Stuart

Jane Doe

Steve Patterson

Dave Smith

Sam Wilks

Kurt Jefferson

Sam Stuart

Jane Stuart

Dave Davis

Sam Patterson

Tom Jefferson

Jane Stuart

Maggie Jefferson

Mary Wilks

Neil Patterson

Corey Davis

Steve Jacobs

Jane Jenkins

John Jacobs

Neil Smith

Corey Wilks

Corey Smith

Mary Patterson

Jane Stuart

Travis Arnold

John Robinson

Travis Arnold

---------------------------------