How to split
try2[Works with issue]>
try3[No Work]>
sep = "," at only ")," and exclude "%," ?text = "METAL (3.25%,a/d=13/1),IT(2.31%,a/d=10/0),HEALTHCAREINDEX(1.32%,a/d=13/7)"try1[No Work] > textSplit = text.split(r',') includes "%,"
try2[Works with issue]>
textSplit = text.split(r'),') omits ")" at the end .How to add ")" back to the string.try3[No Work]>
textSplit = text.split(r'/(?<=[)],)/gm') positive lookahead doesn't split only at "),"import re
import numpy as np
def randomColor(x):
rColor = list(np.random.random(size=3) * 256)
return f'<span style = "color:rColor">{x}</span>'
def spanColor(text):
textSplit = text.split(r'/(?<=[)],)/gm')
print(text)
print(textSplit)
textSplit_lst = [randomColor(x) for x in textSplit]
textSplit_str = ",".join(textSplit_lst)
return textSplit_str
def regex_func():
print("Start")
regStr = "METAL (3.25%,a/d=13/1),IT(2.31%,a/d=10/0),HEALTHCAREINDEX(1.32%,a/d=13/7)"
regLst = spanColor(regStr)
print(f"regLst = {regLst}")
regex_func()
