Skip to content Skip to sidebar Skip to footer

How To Add Tag For Numbers Which In Brackets Using Python Regex?

The default strings is: strings123[abc123def456]strings456 Add tag for number: strings[abc123def456]strings

Solution 1:

Search by this:

(\d+)

and replace by :

<span>\1</span>

Regex Demo

Sample Source:

import re
regex = r"(\d+)"
test_str = "strings[abc123def456]strings"
subst = "<span>\\1</span>"
result = re.sub(regex, subst, test_str, 0)
if result:
    print (result)

Post a Comment for "How To Add Tag For Numbers Which In Brackets Using Python Regex?"