0

How does the re.sub work?...does it change the string according to the modified raw string or vice versa????

regular expressions substitution

7th Jun 2017, 11:54 PM
thomo
thomo - avatar
2 Réponses
+ 1
here is what the documentation says: re.sub(pattern, repl, string, count=0, flags=0) Return the string obtained by replacing the leftmost non-overlapping occurrences of pattern in string by the replacement repl. If the pattern isn’t found, string is returned unchanged. repl can be a string or a function; if it is a string, any backslash escapes in it are processed. That is, \n is converted to a single newline character, \r is converted to a carriage return, and so forth. Unknown escapes such as \& are left alone. Backreferences, such as \6, are replaced with the substring matched by group 6 in the pattern.
8th Jun 2017, 12:39 AM
Ulisses Cruz
Ulisses Cruz - avatar
8th Jun 2017, 12:45 AM
Ulisses Cruz
Ulisses Cruz - avatar