Special Case to Replace String Using Python with Regex -


i'd replace decimal point not period in 1 content.

for example:

original content:

this cake. 1.45 dollars , 2.38 kg. 

replaced content:

this cake. cost 1<replace>45 dollars , 2<replace>38 kg. 

how can use python regex ?

thank much.

use re.sub lookaround assertions:

>>> import re >>> s = 'this cake. 1.45 dollars , 2.38 kg.' >>> re.sub(r'(?<=\d)\.(?=\d)', '<replace>', s) 'this cake. 1<replace>45 dollars , 2<replace>38 kg.' 

Comments

Popular posts from this blog

Unable to remove the www from url on https using .htaccess -