Phone-Number-Search

Sat 17 May 2025

title: "Phone Number Search" author: "Raja CSP Raman" date: 2019-04-20 description: "-" type: technical_note draft: false


import re
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()
Allison Neu 555-8396 …

Category: regex

Read More

Regex-Groups

Sat 17 May 2025

title: "Regex Groups" author: "Raja CSP Raman" date: 2019-04-20 description: "-" type: technical_note draft: false


import re
names = ['A2B8']

for name in names:
    m = re.match("^[A-Z]\d[A-Z]\d", name)

    if(m):
        print(m.groups())
        print('matched : ', name)
()
matched :  A2B8


Score: 0

Category: regex

Read More

Remove Numbers-9552

Sat 17 May 2025

title: "Remove Numbers" author: "Raja CSP Raman" date: 2019-04-20 description: "-" type: technical_note draft: false


content = '15. TFRecord in Tensorflow'
content
'15. TFRecord in Tensorflow'
import re
result = re.sub(r'\d+\.', '', content)
result.strip()
'TFRecord in Tensorflow'
content2 = """1. Cross Entropy Loss Derivation

2. How to split a tensorflow model …

Category: regex

Read More

Remove Symbols

Sat 17 May 2025

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!"
content
'This device is costing only 12.89$. This is fantastic!'
import re
re.sub(r'[^\w]', ' ', content)
'This device is costing only 12 89 …

Category: regex

Read More

Search

Sat 17 May 2025

title: "Search" author: "Raja CSP Raman" date: 2019-04-20 description: "-" type: technical_note draft: false


import re
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'))
toronto …

Category: regex

Read More

Simple-Match

Sat 17 May 2025

title: "Simple Match" author: "Raja CSP Raman" date: 2019-04-20 description: "-" type: technical_note draft: false


import re
content = "Eminem means positive"
a = re.search('^Em.*ve$', content)
if(a):
    print('matched')
else:
    print('not matched')
matched

More situations

  • Match Canadian postal code
  • Phone number
  • Start with /home
  • Contains /User/raja


Score …

Category: regex

Read More

Simple-Regex

Sat 17 May 2025

title: "Simple Regex" author: "Raja CSP Raman" date: 2019-04-29 description: "-" type: technical_note draft: false


import re
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)
15 22 …

Category: regex

Read More

Specific Pattern 1

Sat 17 May 2025

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


import re
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 …

Category: regex

Read More
Page 2 of 2

« Prev