0

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!

2
  • And what's the overall goal? What do you intend to accomplish with the parameter name? Commented Mar 9, 2010 at 22:29
  • 1
    What about function names in side comments: /* comment translate() */? And in string literals: str = " string translate() "? Commented Mar 9, 2010 at 22:34

1 Answer 1

1

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\().*?(?=\))

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

1 Comment

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

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.