I have weird list of items and lists like this with |
as a delimiters and [[ ]]
as a parenthesis. It looks like this:
| item1 | item2 | item3 | Ulist1[[ | item4 | item5 | Ulist2[[ | item6 | item7 ]] | item8 ]] | item9 | list3[[ | item10 | item11 | item12 ]] | item13 | item14
I want to match items in lists called Ulist*
(items 4-8) using RegEx and replace them with Uitem*
. The result should look like this:
| item1 | item2 | item3 | Ulist1[[ | Uitem4 | Uitem5 | Ulist2[[ | Uitem6 | Uitem7 ]] | Uitem8 ]] | item9 | list3[[ | item10 | item11 | item12 ]] | item13 | item14
I tryied almost everything I know about RegEx, but I haven't found any RegEx matching each item inside if the Ulists. My current RegEx:
/Ulist(d+)[[(s*(|s*[^s|]*)*s*)*]]/i
What is wrong? I am beginner with RegEx.
It is in Python 2.7, specifically my code is:
def fixDirtyLists(self, text):
text = textlib.replaceExcept(text, r'Ulist(d+)[[(s*(|s*[^s|]*)*s*)*]]', r'Ulist1[[ U3 ]]', '', site=self.site)
return text
text
gets that weird list, textlib
replaces RegEx with RegEx. Not complicated at all.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…