Learn practical skills, build real-world projects, and advance your career
Updated 5 years ago
import re
Q1.
Write a regular expression to match all the files that have either .exe, .xml or .jar extensions. A valid file name can contain any alphabet, digit and underscore followed by the extension.
files = ['employees.xml', 'calculator.jar', 'nfsmw.exe', 'bkgrnd001.jpg', 'sales_report.ppt']
result = []
# write your code here
# print result - result should only contain the items that match the pattern. In this case, result should be ['employees.xml', 'calculator.jar', 'nfsmw.exe']
print(result)
Q2.
Write a regular expression to match all the addresses that have Koramangala embedded in them.
Strings that should match:
- 466, 5th block, Koramangala, Bangalore
- 4th BLOCK, KORAMANGALA - 560034
Strings that shouldn't match:
- 999, St. Marks Road, Bangalore
addresses = ['466, 5th block, Koramangala, Bangalore', '4th BLOCK, KORAMANGALA - 560034', '999, St. Marks Road, Bangalore']
result = []
# write your code here
# print result - result should only contain the items that match the pattern
print(result)