Phone-Number-Search
title: "Phone Number Search"
author: "Raja CSP Raman"
date: 2019-04-20
description: "-"
type: technical_note
draft: false
fh = open("sample_phone_book.txt")
for line in fh:
if re.search(r"J.*Neu",line):
print(line.rstrip())
if re.search(r"a*Neu",line):
print(line.rstrip())
fh.close()
Read More
Regex-Groups
title: "Regex Groups"
author: "Raja CSP Raman"
date: 2019-04-20
description: "-"
type: technical_note
draft: false
names = ['A2B8']
for name in names:
m = re.match("^[A-Z]\d[A-Z]\d", name)
if(m):
print(m.groups())
print('matched : ', name)
Score: 0
Read More
Remove Numbers-9552
title: "Remove Numbers"
author: "Raja CSP Raman"
date: 2019-04-20
description: "-"
type: technical_note
draft: false
content = '15. TFRecord in Tensorflow'
'15. TFRecord in Tensorflow'
result = re.sub(r'\d+\.', '', content)
content2 = """1. Cross Entropy Loss Derivation
2. How to split a tensorflow model …
Read More
Remove Symbols
title: "Remove Symbols"
author: "Raja CSP Raman"
date: 2019-04-20
description: "-"
type: technical_note
draft: false
content = "This device is costing only 12.89$. This is fantastic!"
'This device is costing only 12.89$. This is fantastic!'
re.sub(r'[^\w]', ' ', content)
'This device is costing only 12 89 …
Read More
Search
title: "Search"
author: "Raja CSP Raman"
date: 2019-04-20
description: "-"
type: technical_note
draft: false
data = [
"name['toronto'] = 'One'",
"state['ontario'] = 'Two'",
"country['canada']['ca'] = 'Three'",
"extra['maple'] = 'Four'"
]
REGEX = re.compile(r"\['(?P<word>.*?)'\]")
for line in data:
found = REGEX.search(line)
if found:
print(found.group('word'))
Read More
Simple-Match
title: "Simple Match"
author: "Raja CSP Raman"
date: 2019-04-20
description: "-"
type: technical_note
draft: false
content = "Eminem means positive"
a = re.search('^Em.*ve$', content)
if(a):
print('matched')
else:
print('not matched')
More situations
- Match Canadian postal code
- Phone number
- Start with /home
- Contains /User/raja
Score …
Read More
Simple-Regex
title: "Simple Regex"
author: "Raja CSP Raman"
date: 2019-04-29
description: "-"
type: technical_note
draft: false
pattern = 'awesome'
content = 'Duckduck go is awesome and it is getting better everyday'
match = re.search(pattern, content)
#print(match)
start = match.start()
end = match.end()
#print(match.string)
print(start, end)
Read More
Specific Pattern 1
title: "Specific Pattern 1"
author: "Raja CSP Raman"
date: 2019-04-20
description: "-"
type: technical_note
draft: false
source: https://stackoverflow.com/questions/56232268/extract-word-form-string-using-regex-word-boundaries-in-python
fn = "DC_QnA_bo_v.15.12.3_DE_duplicates.xlsx"
rgx = re.compile('\b_[A-Z]{2}\b')
print(re.findall(rgx, fn))
rgx = re.compile('(?<=_)[A-Z]+(?=_)')
print …
Read More