0
text = "abcde"
var = "X"
text = re.sub("b(c)d", var, text)

Actual output: aXe
Wanted output: abXde

It's replacing the whole pattern, I only want it to replace group 1 of the pattern. How do I make regex do this?

1 Answers1

0

I guess this will do the job:

^([a])([b])([^\n]+)([a])([b])$

for verification you can use regex101 website.

FZL
  • 11
  • 2