0

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.?

1
  • Please can you explain yourself more so we can all understand? ;-) Commented Apr 19, 2011 at 12:40

3 Answers 3

1

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

Sign up to request clarification or add additional context in comments.

12 Comments

Thanks @Town, Can we do "Chitralekha.in" dynamic after facebook link Can I get username dynamic replace with fixed "chitralekha.in" in above example
@Abhishek: You mean you want to start with www.facebook.com/username rather than just www.facebook.com ?
@Abhishek: Yes, see the update to my answer. You'll have to change the [^<]* part to match with what you're expecting in your string - this looks for anything that isn't a <.
@Town I want like this If URL www.facebook.com/abcd I want result lik <a href='facebook.com/abcd'; target='_blank'> abcd </a>.. in this case Username is "abcd" so It should be dynamic. please gave me soultion.
@Abhishek: That's what the update already does! See here
|
0

It can be done with a regular expression. You look for the text that you want to replace and you do it.

5 Comments

i'm not a genious in regexp, but you can filter literal characters like this: \bTEXT\b
Thanks @Erick for suggestion. I trying regular expression.. in my Html tag <label id='lblfacebook'>www.facebook.com/chitralekha.in</label> I trying replace with <label id='lblfacebook'><a href='www.facebook.com/chitralekha.in' >chitralekha.in</a></label>..
@Eric Frick: You can edit your answer rather than posting multiple answers.
how can i add an comment to a post?
@Eric Frick: You can either click the 'edit' link below your answer to change it, or if you want to add a comment then just keep doing what you've done here ;)
0
$("#selector").filter(function(){
 return this.value.match(\bhttp://www.facebook.com/\b)
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.