Skip to content
Advertisement

Detecting a specific string with regex in python

I have a csv file with below string structure:

Modem Switch (MMA-213-MML-NW-Match-New Year)(32655)(12532)
Modem Switch3 (MMA-1234-431-NW-Match-New Month)(32655)(12532)
Modem Switch3 (MMA-1234-431-NW-Match-New1 Month)(32655)(12532)
Modem Switch3 (MMA-1234-431-NW-Match-New Month 2)(32655)(12532)
....

I want to get any string which comes after Match: For example the expected result shared as below:

New Year
New Month
New1 Month
New Month 2

with below code it is not possible to get my relative string:

matches = re.findall(r'(Match-)(w+)', inp, flags=re.I)

Advertisement

Answer

This works:

import re
inp = "Modem Switch3 (MMA-1234-431-NW-Match-New Month)(32655)(12532)"
matches = re.findall(r'Match-(.+?))', inp, flags=re.I)

gives

['New Month']
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement