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 7947339
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T01:24:11+00:00 2026-06-04T01:24:11+00:00

For example: There is a page that lists some items with colours. Some are

  • 0

For example: There is a page that lists some items with colours. Some are listed as Nav some are listed as Navy.

$('.ProductDetails a').each(function() {
    var text = $(this).text();
    $(this).text(text.replace("Nav", "Navy")); 
});

Will result in all ‘Nav’ being changed to Navy – great!

But it will also result in ‘Navy’ being changed to Navyy. (i.e. it replaces the ‘nav’ in navy to navy and leaving the ‘y’ after the ‘nav’ has been replaced)

Is there a way to stop this using the technique above or will I have to change the script to account for these double ups.

My current solution is to add a space after Nav $(this).text(text.replace("Nav ", "Navy"));

But this isn’t ideal because some of the items may have a / after them and no space.

  • 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-06-04T01:24:13+00:00Added an answer on June 4, 2026 at 1:24 am
    $('.ProductDetails a').each(function() {
        var text = $(this).text();
        $(this).text(text.replace(/^Nav$/g, "Navy")); 
    });
    

    Or:

        $(this).text(text.replace(/\sNav\s/g, "Navy")); 
    

    Or:

        $(this).text(text.replace(/\bNav\b/g, "Navy")); 
    

    There are many other ways…

    Note that you can use this text overload:

    $('.ProductDetails a').text(function(index, old) {
        return old.replace(/\sNav\s/g, "Navy");
    });​
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

there's a list of items on a page, some blank, with one example being:
I have a page that lists over 100 items and I need to dynamically
http://www.ericmmartin.com/projects/simplemodal/ There's two examples near the bottom of the page that show how to
On the Groovy example page there is an example of how to use Groovy
From page 90 of Erlang Programming by Cesarini and Thomson, there is an example
is there any example on using java method to call rhino-javascript function and return
I have a page that lists a bunch of files. This page can be
The idea is to create a DOM-like tree. But there are some restrictions, that
Learn You a Haskell mentions difference lists (search for this term on that page),
Are there any good examples of mvc routing wherein every 404 page not found

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.