tags:

views:

46

answers:

2

Hi there:

I am working on getting parameter from a function string. For example, my function is named "translate". So all I need to do is to get everything inbetween "translate(" and ")". Is there a way that i can use regex to do that? So far I have something like:

"/translate\((?<keyName>*)\)/i"

Unfortunately it's not working. Can anybody help me with this one?

Thanks a lot!

+1  A: 

translate\((.*?)\) will match the whole function call and capture the parameter into backreference 1. So you can replace it with \1 if you want to extract the parameter.

If you want to match only the parameter and the regex engine you're using supports look-behinds/look-aheads, you can use this one: (?<=translate\().*?(?=\))

tiftik
Note that these solutions obviously don't support escaping ). So they won't match or capture translate("<*)))><") as intended.
tiftik
A: 

Thanks guys. Additional information: I am using PHP. What I am doing is writing a code search all the files and get the parameters being used.

Xi
This isn't an answer. If you want to clarify, edit the original question.
Bryan Oakley