2

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?

1

2 Answers 2

2

Try using

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

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

Sign up to request clarification or add additional context in comments.

Comments

2

Rather than the lazy star, you might as well get along with a digit class directly (the function build_textual_marker takes a number parameter, doesn't it?):

\[xxxcixxx\[(\[_'\d+'\])\s(\[_'\d+'\])\]xxxcixxx\]

See a demo on regex101.com.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.