How can I replace occurrences of white-space with underscores, but only in a specific part of the line/string, using python?
source string:
* this is the line with a [[filename01 as a wiki type link]] inside
I'd like to convert to:
* this is the line with a [[filename01_as_a_wiki_type_link]] inside
In the end came up with this:
res = re.sub(r'(?:.*)?(?<=\[\[[a-zA-Z0-9]+)\s', r'_', line)
And this is what I expected it to do:
(?:.*)?
=> re.sub don't do anything at all with this, no matter if it's in the line or not
(?<=\[\[[a-zA-Z0-9]+)\s+
=> re.sub do something with the whitespace(s) "\s" that comes after alphanumerical characters after the (escaped) square brackets.
And this gives me: "look-behind requires fixed-width pattern" meaning that I have to know the length of the string inside the square brackets which I don't.
My question is now: what is the right approach for this? I want to replace whitespaces by underscores but only inside a square-brackets-enclosed string of random length.