python - Regex multiline replace -


so have this:

z='===hello   there===,   how ===you===?' 

and want be:

z='<b>hello   there<\b>,   how <b>you<\b>?' 

i tried doing this:

z = re.sub(r"\={3}([^\$]+)\={3}", r"<b> \\1 </b>", z, re.m)   

and works sort of got instead:

z='<b>hello   there===,   how ===you<\b>?'   

i'm still new believe it's ^ , $ makes match beginning , end of string. how change matches ones in middle?

re.sub(r"\={3}([^\$]+?)\={3}", r"<b> \\1 </b>", z, re.m) 

copy python docclick here:

*?, +?, ?? '*', '+', , '?' qualifiers greedy; match text possible. behaviour isn’t desired; if re <.*> matched against '<h1>title</h1>', match entire string, , not '<h1>'. adding '?' after qualifier makes perform match in non-greedy or minimal fashion; few characters possible matched. using .*? in previous expression match '<h1>'.


Comments

Popular posts from this blog

php - cannot display multiple markers in google maps v3 from traceroute result -

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -