Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3618780
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T22:47:45+00:00 2026-05-18T22:47:45+00:00

hi i am trying to highlight links in a text using RegEx ,For this

  • 0

hi i am trying to highlight links in a text using RegEx ,For this I tried with match() method and replace() method,
but i didn’t get it.plz any one can help me.

<head runat="server">
    <title></title>
               <script type="text/javascript" >

        function findReplace() {
            var srcString = document.getElementById('new').innerHTML;
            var pattern = new RegExp("<[^<]+</a>", 'ig');
            var newString = srcString.match(pattern);
            for (var i = 0; i < newString.length; i++) {
              var replaced = srcString.replace(pattern, '<div style="background-color: yellow; display: inline; font-weight: bold;"> ' + newString[i] + ' </div>')

            document.getElementById('new').innerHTML = replaced

        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <input type='button'  id='btn'value='Match' onclick="findReplace()"  />
    <div id='new'>
    Finally we  have succeeded! <a href='#'>Remember</a> that if you just want to replace one word,
     you should use a string or normal regular expression as your searchFor parameter. However, 
     if you want to replace <a href='#'>google</a> be sure to write a <a href='#'>regularexpression</a> and append a little g at the end!
     </div>
    </form>
</body>
</html>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T22:47:46+00:00Added an answer on May 18, 2026 at 10:47 pm

    based on your work, here is a solution :

    function findReplace() {
    
         var pattern = new RegExp("(<a[^<]+</a>)", 'ig');
         document.getElementById('new').innerHTML = document.getElementById('new').innerHTML.replace(pattern, '<div style="background-color: yellow; display: inline; font-weight: bold;">$1</div>');
     }
    

    If I were you, I would use the DOM with document.getElementsByTagName(‘a’) instead of Regex + innerHTML property and your regex won’t match :

    <a href="efefe.html"><strong>okokok</strong></a>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im in a spot of bother trying to get this Jquery highlight to work
I keep trying to get rid of this keybinding but setting it to nil
I'm trying to write a Google chrome extension so that I can highlight text
I am trying to figure out how to get my PBS scripts to highlight
I'm trying to highlight all links that do not have a href set, or
I'm trying to get JQuery to highlight an element based on the link ID
I am trying to get an ASP.NET 3.5 ListView control to select and highlight
I'm trying to highlight the days on my jQuery datepicker calendar which are associated
I'm trying to use jQuery validation to highlight the labels for my radio buttons
I'm trying to find a Java library to highlight code. I don't want to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.