regex - String Replace in Python - Using Re.sub - having additional unnecessary characters -


i using python 2.7 here have string "portalcolumn":"col-0","portlet": , , trying replace "col-0" "col-1" or "col-2".. so, trying use python's s = re.sub("col-(.*?)", column, portletjsonstring)

it replaces "col-0" "col-10" when pass "col-1" in column variable.. , portletjsonstring string in want replace. see after re.sub call : "portalcolumn":"col-10","portlet"

what correct way replace string guys? keeps 0 intact.

thanks help.

i figured out :-)

just used .? instead of .*? .. unnecessary * in there.

also, kenneth mentioned, can use \d+


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -