I’m trying to search a string for numbers, and when finding them, wrap some chars around them, e.g.
a = "hello, i am 8 years old and have 12 toys"
a = method(a)
print a
"hello, i am \ref{8} years old and have \ref{12} toys"
I’ve looked at the re (regular expression) library, but cannot seem to find anything helpful… any cool ideas?
This is pretty basic usage of the
.submethod:The parethesis around the
\d+number pattern create a group, and the\1reference is replaced with the contents of the group.