Check whether modification in re.sub occurred

后端 未结 1 1932
[愿得一人]
[愿得一人] 2021-01-18 10:13

The Python function re.sub(pattern, replacement, string) returns the modified string with the matched pattern replaced with the replacement. Is there any easy w

相关标签:
1条回答
  • 2021-01-18 10:52

    Depends on the version. In <= 2.6, you have to couple sub() with match() or search() to get count.

    If you are using Python 2.7, you can use subn(), which will return a tuple of (new_string, number_of_subs_made).

    Not sure about 3+.

    0 讨论(0)
提交回复
热议问题