0

Im having trouble to create the regex pattern (javascript) to capture the text between rounded bracket. Hereby the string value:

var pattern = /->__\(([^)]+)\)/g;
var value = "Line 54:'label' => $this->helper('cms')->__('Images (%s)', implode(', ', $labels)),".match(pattern);

I need the output value as below

->__('Images (%s)', implode(', ', $labels))
asked May 29, 2014 at 11:43

2 Answers 2

1

var pattern = /->__.*\)\)/; will work based on the fragment you posted, but I suspect that this question is really off-topic as it's a general javascript/regex question.

answered May 29, 2014 at 12:08
1
  • Apologize. Yeah, it had a bit complexity than just a simple matching. Commented May 29, 2014 at 15:24
1

The only way I could see is to do two times regex as javascript don't support look behind regex.

var pattern = /__[^"]*/g;
var value = "Line 54:'label' => $this->helper('cms')->__('Images (%s)', implode(', ', $labels)),".match(pattern);
if(value.length){
 value = value[0].replace(/,$/,"");
}
answered May 29, 2014 at 13:49
1
  • Green, appreciate for your effort. I tried many patterns but to no avail. I'll keep trying, thanks anyway. Commented May 29, 2014 at 15:30

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.