Is there a way to do substitution on a group?
Say I am trying to insert a link into text, based on custom formatting. So, given something like this:
This is a random text. This should be a [[link somewhere]]. And some more text at the end.
I want to end up with
This is a random text. This should be a <a href="/link_somewhere">link somewhere</a>. And some more text at the end.
I know that '\[\[(.*?)\]\]'
will match stuff within square brackets as group 1, but then I want to do another substitution on group 1, so that I can replace space with _
.
Is that doable in a single re.sub
regex expression?