I have a string , which may or may not be valid HTML , but it should contain a Title tag.
I want to replace the content of the header with new content.
Example 1:
lorem yada yada <title>Foo</title> ipsum yada yada
Should turn into:
lorem yada yada <title>Bar</title> ipsum yada yada
Example 2:
lorem yada yada <title attributeName="value">Foo</title> ipsum yada yada
Should turn into:
lorem yada yada <title attributeName="value">Bar</title> ipsum yada yada
I don't want to parse html with regex - just replace the title tag ... Please don't send me here ...
EDIT: After numerous voices and a great patronizing attitude -
I know (as allowed in the original post) that usually Regex is not a way to handle HTML. I am open to any solution that solves my problem, but so far every jQuery / DOM solution has not worked. Being “right” is not enough.
source share