Have a look at this fiddle /
Here I want to split the characters which starts with [*
or [*#
and ends with *]
. The current regular expression split the string which starts with [*#
but not [*
. I have tried the following patterns,
/(\[\*\#*[a-zA-Z0-9]+\*\])/g
/(\[\*\#{0,1}[a-zA-Z0-9]+\*\])/g
Thanks in advance.
Have a look at this fiddle http://jsfiddle/yeXWv/
Here I want to split the characters which starts with [*
or [*#
and ends with *]
. The current regular expression split the string which starts with [*#
but not [*
. I have tried the following patterns,
/(\[\*\#*[a-zA-Z0-9]+\*\])/g
/(\[\*\#{0,1}[a-zA-Z0-9]+\*\])/g
Thanks in advance.
Share asked May 29, 2013 at 14:26 moustachemanmoustacheman 1,4644 gold badges23 silver badges47 bronze badges2 Answers
Reset to default 4Try making the hash character optional:
/(\[\*\#?[a-zA-Z0-9 ]+\*\])/g
Edit: added missing white space :-)
You forgot to allow for spaces, which was the real problem -- not the missing # character.
/(\[\*\#?[a-zA-Z0-9 ]+\*\])/g
That will preserve the [*...*]
strings in the output array. To omit them, remove the parentheses:
/\[\*\#?[a-zA-Z0-9 ]+\*\]/g
http://jsfiddle/mblase75/zU576/