The Python re.sub(pattern, replacement, string) function returns the changed string with the replaced pattern with replacement. Is there an easy way to check if a match has occurred and what modification has been made? (And also how many changes)
re.sub(pattern, replacement, string)
Depends on the version. In <= 2.6 you need to connect sub() with match() or search() to get the score.
sub()
match()
search()
If you are using Python 2.7, you can use subn() , which will return a tuple (new_string, number_of_subs_made).
subn()
Not sure about 3+.
Source: https://habr.com/ru/post/1483261/More articles:Gzip browser decompression skills / speed - performanceUniform distance with Matplotlib and TeX - pythonReplace all without regex where I can use G - javascriptSurface Datatable RowSelect Event - eventsWhat (if any) is javascript keydown event priority? - javascriptpython, wrap and object to list if it is not iterable - pythonPerl dynamic link to array - arraysWMI query to determine DNS servers without null records - wmiHow to get RateLimitStatus object on Twitter4j? - javaRails link to file in shared folder - ruby-on-railsAll Articles