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))
2 Answers 2
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.
-
Apologize. Yeah, it had a bit complexity than just a simple matching.Leongelis– Leongelis2014年05月29日 15:24:47 +00:00Commented May 29, 2014 at 15:24
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
Mr_Green
1,6154 gold badges31 silver badges50 bronze badges
-
Green, appreciate for your effort. I tried many patterns but to no avail. I'll keep trying, thanks anyway.Leongelis– Leongelis2014年05月29日 15:30:47 +00:00Commented May 29, 2014 at 15:30
default