i use python regular expression problem. you'd expect result of import re re.sub("s (.*?) s", "no", "this string") to "this no string", right? in reality it's "thinotring". sub function uses entire pattern group replace, instead of group want replace. all re.sub examples deal simple word replacement, if want change depending on rest of string? in example... any appreciated. edit: the look-behind , look-forward tricks won't work in case, need fixed width. here actual expression: re.sub(r"<a.*?href=['\"]((?!http).*?)['\"].*?>", 'test', string) i want use find links in string don't begin http, can prefix in front of links (to make them absolute rather relative). your regex matches first s last s, if replace match "no", "thinotring". the parentheses don't limit match, capture text matched whatever inside them in special variable...