AliGH AliGH - 11 months ago 31
Python Question

Matching a complex expression in python regex

I have to create a unique textual marker in my document using python 2.7, with the following function:

def build_textual_marker(number, id):
return "[xxxcixxx[[_'" + str(number) + "'] [_'" + id + "']]xxxcixxx]"

the output looks like this :
[xxxcixxx[[_'1'] [_'24']]xxxcixxx]

And then I have to catch any occurrence of this expression in my document. I ended up to the following regular expression but it seems not working fine:

marker_regex = "\[xxxcixxx\[(\[_*?\])\s(\[_*?\])\]xxxcixxx\]"

I was wondering how should I write the correct regex in this case?


Try using

\[xxxcixxx\[\[_'.*?'\] \[_'.*?'\]\]xxxcixxx\]