multi regex replace and split python

mail@pastecode.io avatarunknown
python
2 months ago
1.6 kB
10
Indexable
Never
### --- Simple to Read Version --- ###
import re

txt = "MCMXCXLIXIVIII"

print(
re.sub('(IV)', '{0}❤️', (
re.sub('(IX)', '{0}❤️', (
re.sub('(XL)', '{0}❤️', (
re.sub('(XC)', '{0}❤️', (
re.sub('(CM)', '❤️{0}❤️', txt).format("CM")
)).format("XC")
)).format("XL")
)).format("IX")
)).format("IV").split('❤️')
)

### ------ ###




### --- Standard Version --- ###
import re

txt = "MCMXCXLIXIVIII"

print(re.sub('(IV)', '{0}❤️', (re.sub('(IX)', '{0}❤️', (re.sub('(XL)', '{0}❤️', (re.sub('(XC)', '{0}❤️', (re.sub('(CM)', '❤️{0}❤️', txt).format("CM"))).format("XC"))).format("XL"))).format("IX"))).format("IV").split('❤️'))

### ------ ###




### Prior Tests ###

# print(re.sub('(XL)', '❤️{0}❤️', (re.sub('(CM)', '❤️{0}❤️', txt).format("CM"))).format("XL").split('❤️'))

# re.findall(r'[\w\.-]+@[\w\.-]+', abc)


#print(re.findall(r'CM|XC|XL|IX|IV', txt))

#'❤️{0}❤️', (re.sub('(CM)', '❤️{0}❤️', txt).format("CM"))).format("XL").split('❤️'))


# print(re.sub(r'CM', '❤️{0}❤️', txt).format("CM"))

# print(re.sub(r'CM|XC|XL|IX|IV', '❤️{0}❤️', txt).format("CM").format("XC"))

# print(re.sub(r'(IX)', '{0}❤️', (re.sub(r'(IX)', '{0}❤️', (re.sub(r'(XL)', '{0}❤️', (re.sub(r'(XC)', '{0}❤️', (re.sub(r'(CM)', '❤️{0}❤️', txt).format("CM")).format("XC")).format("XL")).format("IX")).split('❤️'))


# print(re.sub('(XL)', '❤️{0}❤️', (re.sub('(CM)', '❤️{0}❤️', txt).format("CM"))).format("XL").split('❤️'))