1

What I am trying to match is something like this:

public FUNCTION_NAME
FUNCTION_NAME proc near
......

FUNCTION_NAME endp

FUNCTION_NAME can be :

version_etc
version_etc_arn
version_etc_ar

and my pattern is:

pattern = "public\s+" + func_name + "[\s\S]*" + func_name + "\s+endp"

and match with:

match = re.findall(pattern, content)

So currently I find if the fuction_name equals version_etc, then it will match all the version_etc_arn, version_etc_ar and version_etc.....

which means if the pattern is :

"public\s+" + "version_etc" + "[\s\S]*" + "version_etc" + "\s+endp"

then it will match:

public version_etc_arn
version_etc_arn proc near
......

version_etc_arn endp

public version_etc_ar
version_etc_ar proc near
......

version_etc_ar endp

public version_etc
version_etc proc near
......

version_etc endp

And I am trying to just match:

public version_etc
version_etc proc near
......

version_etc endp

Am I wrong? Could anyone give me some help?

THank you!

2
  • Also, you should always be using raw strings when dealing with regexes (to handle escape sequences correctly), and you don't need [\s\S] in Python; . works just like it if you specify re.DOTALL when compiling/using the regex. Commented Feb 1, 2014 at 16:57
  • @TimPietzcker Hi Tim, I modified my question, is it clear now? Commented Feb 1, 2014 at 16:59

1 Answer 1

2

[\s\S]* matches 0-or-more of anything, including the _arn that you are trying to exclude. Thus, you need to require a whitespace after func_name:

pattern = r"(?sm)public\s+{f}\s.*^{f}\s+endp".format(f=func_name)
Sign up to request clarification or add additional context in comments.

1 Comment

Oooh. Format string syntax. Unfortunately, I can only upvote this once.

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.