Regex in replacements: how to use matches


#1

Hello all.

I want to inject a HTML tag after original <body> and I’m using replacements option for it:

replacements:
        - "#~s#<body(.*?)>#<body$1><iframe src='http://localhost:8000'></iframe>"

How can I use matched groups in regex so that I can replay original body attributes?
Or is there a better way?


#2

I found this by trial and error:

#~s#<body(.*?)>#<body\\g<1>><iframe src='http://localhost:8000'></iframe>

Is that \\g<1> syntax simplest? I’m not python fluent. Is there a way to write it simpler?


#3

I usually help myself testing regular expression on this site.