Replace use of regular expressions by string formatting

This commit removes regular expressions and replaces it with Python's string formatting syntax, which makes it easier to maintain and read.