We can easily get the string between two parentheses or brackets using regular expression. This regular expression can be applied in any programming language / scripts like php, javascript,java,perl,python,c#,asp etc.

Regular Expression:
/(([^)]+))/

 /   - Start of the expression
 (  - Match the starting bracket. This bracket escaped with back slash as its one of the key component of RegEx.
 (   - Match the characters as a group
 [^)]  - Match anything except the closing bracket.
 )   - Close the Matching group
 )  - Match closing bracket

This regular expression can be used to get the string between parantheses like below:
 

Javascript

var ca='call_me(123,123)';
var parameters=ca.match(/(([^)]+))/)[1];
alert(parameters);
</script>

PHP

$str='call_me(123,123)';
preg_match('/(([^)]+))/',$str,$matches);
echo $matches[1];


Comments (0)
Leave a Comment

loader Posting your comment...