You may use this:
import re txt = "$2024122201200}" x = re.sub(r'\$(\d+)[}]*', r'\1', txt) print(x) txt = "$2024122201200" x1 = re.sub(r'\$(\d+)[}]*', r'\1', txt) print(x1)
https://www.programiz.com/online-compiler/0fkwe2zixyrrQ