I could really use some help with a Python regular expression problem. You'd expect the result of
import re
re.sub("s (.*?) s", "no", "this is a string")
to be "this is no string", right? But in reality it's "thinotring". The sub function uses the entire pattern as the group to replace, instead of just the group I actually want to replace.
All re.sub examples deal with simple word replacement, but what if you want to change something depending on the rest of the string? Like in my example...
Any help would be greatly appreciated.
Edit:
The look-behind and look-forward tricks won't work in my case, as those need to be fixed width. Here is my actual expression:
re.sub(r"<a.*?href=['\"]((?!http).*?)['\"].*?>", 'test', string)
I want to use it to find all links in a string that don't begin with http, so I can but a prefix in front of those links (to make them absolute rather then relative).