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

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

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -