python - Is there a single function for matching and replacing? -
I am surprised that there is a simple option (like a function call) to match and replace the following example:
& gt; & Gt; & Gt; Import re & gt; & Gt; & Gt; & Gt; & Gt; & Gt; Line = 'file: /// window-D / academic% 20discipline / study% 20 objects / regions / formal% 20systems / math' & gt; & Gt; & Gt; & Gt; & Gt; & Gt; Match = re-match Match (r '^ file: // (. * $$', line)> gt;> gt; match and match.group (1): ... substitution = re.sub ('% 20 ', R' ', match.group (1)) ...>> Thank you .- "ItemProp =" Text ">
I am dodging the question and suggesting that you use something else for it:
gt; line = 'file: /// window-D / academic % 20discipline / study% 20 objects / regions / formal% 20systems / math '> gt;> import urllib >> gt; & gt; Urllib.unquote (line)' file: /// windows- D / academic discipline / study items / regions / formal system / math '
then just close file: //
one piece or str. If possible with the replace
% 20
(space) is probably not the only surviving character here, so after any other work your Rizx Solution Comparison of breaking Switch to a job is better to use the right tools needed to avoid character
Comments
Post a Comment