Finding and removing all occurences of shortcode with javascript


Staff member
I have this shortcode for wordpress.

[shortcodename code="dhgsfy87djh" time="2"][/shortcodename]

This pattern may appear more than once inside a textarea. I need to remove all occurrences of this pattern in the text area. The problem is - I am not a reg ex person. Kindly suggest a regex in to remove all occurrences of this pattern using javasript.

For example the content may be like this:

[shortcodename code="dhgsfy87djh" time="2"][/shortcodename] [shortcodename code="hdfds8f7684768" time="5"][/shortcodename] blah blah [shortcodename code="df87s8bdf78sd" time="8"][/shortcodename]

![This how it is][1]

<a href="" rel="nofollow"></a>

Since i really dont know why this question was down voted, i am assuming someone here was einstien and i am definitely not competing.

So please look at the picture again. say this is the wordpress comment box. Now i need only one occurrence of shortcode to be in there.That too in the beginning only. Say some one copy pastes more of it here and there i want that stripped off. And then i would add only one on the top.

the adding part i am doing, but the stripping i dont know. I used some reg ex but it works in php preg_match however it does not work in javascript.

This is what i used.

/(^[shortcodename[]).([ ]*).(code=\"someprefix_).([A-Za-z0-9]+).([ ]<em>).(time=\"(\d</em>)\"<em>).(]</em>).([/shortcodename])/i;

This is the first question of mine being answered on stackoverflow, so i request everyone for little patience with me. Dont down vote if you dont know the answer, say "i dont know" or "i didnt understand" or "provide more info".

Now please help me with this.