I explain my question with two examples:
Example1:
current string:
var str = 'anything <a href="www.google.com" target="_blank">untitled</a> anything';
// ^ link-name
I want this string:
var newstr = 'anything www.google.com anything';
Example2:
Current string:
var str = 'anything <a href="www.google.com" target="_blank">any thing else</a> anything';
// ^ link-name
I want this string:
var str = 'anything [any thing else](www.google.com) anything';
As you see in the two examples above, untitled
is a keyword. I want if link-name is untitled
, then create a regular URL of that, but if it isn't, then create a pattern-based URL of that.
Note: pattern = [LinkName](LinkAddress)
How can I do that?
Also here is what I have tried:
var newStr = $('<div/>', {html: str}).find("a").replaceWith(function(){
return $(this).attr('href'); // this.href would give absolute path
}).end().text();
My code creates a regular URL from all kind of links. How can I add that condition (checking the link-name for being untitled
or not) to that?