1

I have written a pattern to match typedef followed by any number of characters until it matches the 1st opening braces followed by a * , then a word , closing braces and so on. the pattern is

pattern_funp = re.compile(r"typedef(.*?)\(\*(\w+)\s*\)\s*\(.*?\)\s*")

The above pattern matches acpi_adr_space_setup in the line below which is correct:

typedef acpi_status(*acpi_adr_space_setup) (acpi_handle region_handle,u32 function,void *handler_context,  void **region_context);

but in the below line it matches func which is not what i want:

typedef void *call_rcu_func_t (struct rcu_head *head,void (*func1)(struct rcu_head *head));

The pattern should match the 1st ( followed by * not the 2nd (with *.

2
  • Then what you want to match in the 2nd example? Commented Mar 31, 2016 at 13:33
  • the regex should not match the 2nd example. Commented Apr 1, 2016 at 5:27

1 Answer 1

2

Not sure getting what you mean, but if you want not to match anything after the 1st parenthesis, putting [^(] instead of . should do the trick:

pattern_funp = re.compile(r"typedef([^(]*?)\(\*(\w+)\s*\)\s*\(.*?\)\s*")
Sign up to request clarification or add additional context in comments.

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.