re.sub: Replace One String with Another String Using Regular Expression

re.sub: Replace One String with Another String Using Regular Expression

If you want to either replace one string with another string or to change the order of characters in a string, use re.sub.

re.sub allows you to use a regular expression to specify the pattern of the string you want to swap.

In the code above, I replace 3/7/2021 with Sunday and replace 3/7/2021 with 2021/3/7.

Link to the source code.

Scroll to Top

Work with Khuyen Tran

Work with Khuyen Tran