I want to use regex to match the string of the following format :
(#sometext#)
In the sense ,whatever is there between (# and #) only should be matched.
So, the text:
var s = "hello(%npm%)hi";
var res = s.split(/(\([^()]*\))/);
alert(res[0]);
o/p: hello(%npm%)hi
And
var s = "hello(#npm#)hi";
var res = s.split(/(\([^()]*\))/);
alert(res[0]);
o/p: hello
alert(res[1]);
o/p : (#npm#);
But the thing is , the regex /(\([^()]*\))/ is matching everything between () rather than extracting the string including (# .. #)
like:
hello
(#npm#)
hi
s.match(/\(#([^#]*)#\)/)if you don't need the parts outside the parentheses. (Why are you using.split()? If you really want to do that then maybe something likes.split(/(\(#|#\))/)?)