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!
translate\((.*?)\)will match the whole function call and capture the parameter into backreference 1. So you can replace it with\1if 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\().*?(?=\))