文字列内の整数のみを文字列に置き換える方法
私のスクリプト:
x="the number 1234, today the 909090 of the value of the 90.94"
# by the way the has to be proposed to get the123abd 123the" by a string "ItWasanINT""
re.sub(r'\b\d+(?!\.\d+)\b','ItWasanINT',x)
...機能しない
文字列内の整数のみを文字列に置き換える方法
私のスクリプト:
x="the number 1234, today the 909090 of the value of the 90.94"
# by the way the has to be proposed to get the123abd 123the" by a string "ItWasanINT""
re.sub(r'\b\d+(?!\.\d+)\b','ItWasanINT',x)
...機能しない
「数字」が前に付いていない数字を除外することをお勧めします。コンボであり、「.number」コンボが後に続かない:
re.sub(r'\b(?<!\d\.)\d+(?!.\d)\b','ItWasanINT', x)
結果:
>>> import re
>>> x="the number 1234, today the 909090 of the value of the 90.94"
>>> re.sub(r'\b(?<!\d\.)\d+(?!\.\d)\b','ItWasanINT',x)
'the number ItWasanINT, today the ItWasanINT of the value of the 90.94'