regexpython-refindalltextmatching

include searched regex text also in output


I'm using regex re.findall(r"[0-9]+(.*?)\.\s(.*?)[0-9]+", text) to get below text

8    EXT./INT. MONORAIL - MORNING 8
9    EXT. CITY SCAPE/MONORAIL - CONTINUOUS 9

But my current output doesn't have the prefix and suffix numbers. I'm trying to have the prefix digits also in the output as follows.

9    EXT. CITY SCAPE/MONORAIL - CONTINUOUS 

Any help greatly appreciated! Thanks in advance.

(The current output is given below)

current output


Solution

  • You can use

    (?m)^([0-9]+)\s*(.*?)\.\s(.*?)(?:\s*([0-9]+))?$
    

    See the regex demo. *Details: