تابع () sub(The sub() Function)
عملکرد sub()
مطابق با
متن انتخابی شما:
مثال
Replace every white-space character with the number 9:
import re
txt = "The rain in Spain"
x = re.sub("s",
"9", txt)
print(x)
شما می توانید تعداد تعویض ها را با تعیین کردن کنترل کنید
شمار
پارامتر:
مثال
Replace the first 2 occurrences:
import re
txt = "The rain in Spain"
x = re.sub("s",
"9", txt, 2)
print(x)