Reputation: 5202
Hello I want to replace Website Link with some Html text.
I want to replace Link with specific word
for eq. I have facebook URL as below
http://www.facebook.com/chitralekha.in
I want to replace this http://www.facebook.com/
URL with
<a href='http://www.facebook.com/chitralekha.in'> chitralekha.in </a>
in every place in Html page.
I have facebook label with facebook Link
<label id="lblfacebook">www.facebook.com/chitralekha.in</label>
I want it replace with
<label id="lblfacebook"> <a href='www.facebook.com/chitralekha.in'> chitralekha.in</a></label>
my website URL is fixed for example. http://www.facebook.com or http://facebook.com.
How can achieve it using Jquery regular expression.?
Upvotes: 0
Views: 622
Reputation: 14906
I think this is what you're after: Demo
var re = new RegExp("(http:\/\/(?:www\.)?facebook.com)","gi");
$("body").html($("body").html().replace(re, "<a href='$1/chitralekha.in'> chitralekha.in </a>"));
And for grabbing the username too: Demo
Upvotes: 1
Reputation: 857
$("#selector").filter(function(){
return this.value.match(\bhttp://www.facebook.com/\b)
});
Upvotes: 0
Reputation: 857
It can be done with a regular expression. You look for the text that you want to replace and you do it.
Upvotes: 0