I have following function into to get the text between tags but it is returing tag as well so anyone tell me whtat is wrong in regex expression.
String.prototype.getTextBetweenTags = function (tagname) {
var pattern = "<" + tagname + " ?.*>(.*)</" + tagname + ">";
return this.match(pattern)[0];
}
return <title>hello</title>
should return just Hello
The first element of the result is the entire string. Element 1 is the contents of the first capturing group.
Try this:
Also, don’t use regex to parse HTML. There are hundreds of ways that your regular expression could break.