0

I'm completely stumped as to how to do this. I've been trying for a while, but can't find a suitable way.

So, let's say that I have a pattern representing a function with two arguments: function_name(arg0, arg1).

How can I get the values of arg0 and arg1?

Sample input would look like function_name(10, 20), function_name(function_name(15 + 2, 16), 6) and such.

Another pattern would be function_2[arg0](arg1).

So basically, how can I find strings that match this sort of pattern and extract the values of the arguments?

asked Jul 12, 2016 at 2:04

1 Answer 1

1

you can use module re for regex pattern matching:

In [27]: import re
 ...: s='function_name(10, 20)'
 ...: m=re.search(r'\((.*),(.*)\)', s)
 ...: m.groups()
Out[27]: ('10', ' 20')
In [28]: arg1, arg2 = m.groups()
 ...: print arg1, arg2
 ...: 
10 20
answered Jul 12, 2016 at 2:20
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.