Detecting a specific string with regex in python

Tags: , , , ,



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)

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']


Source: stackoverflow