I have this regular expression ^<+[a-zA-z=\" ]+> I need it to replace text in this string <span class="myclass">Some text< /span>.
I just want to remove the spans and get that Some text, this is my code:
var text = "<span class=\"myclass\">Some text</span>";
var myText = text.replace(/^<+[a-zA-z=\" ]+>/,"").replace("</span>","");
I searched for this for about an hour but I cant find where my error is. Note that I just cant type the span tag so I made spaces in front their open bracket.
And I know that I can type:
var someVar = $(".myClass").html();
but I need the regexp, so please help me!
< span ...>...< /span>) or not.<span class=\"myclass\">Some text</span>then the regular expression works fine (see jsfiddle.net/aWHkj/2, it removes the opening<span>tag). Only removing the closing</span>tag does not work because you have a trailing space in your search string:"</span> ". If I remove that it seems to work fine: jsfiddle.net/aWHkj. Since you didn't explain what the problem is, I don't know if this helps though.