AliGH AliGH - 7 months ago 12
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?

Answer

Try using

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

Demo: http://regexr.com/3d887

Comments