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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T03:10:44+00:00 2026-06-05T03:10:44+00:00

Possible Duplicate: how to replace last occurence of a word in javascript? I have

  • 0

Possible Duplicate:
how to replace last occurence of a word in javascript?

I have a string, for example: “345,456,678,345,345,678343,232″

I need to remove the last occurring of 345 (in this example in the middle but can be nay where in the string) from the string. Thought about using RegEx but can’t find the right pattern and couldn’t find the solution anywhere.

Can any one help with this?

p.s. I know i can use JavaScript string manipulation for this, but I think that this is what RegEx for…

Thank you…
Erez

  • 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-05T03:10:46+00:00Added an answer on June 5, 2026 at 3:10 am

    Modified from the top answer of how to replace last occurrence of a word in javascript?:

    function removeLast(str, target) {
        return str.replace(new RegExp("(.*)"+target), "$1");
    }
    

    This uses the greediness of .* — it will try to grab as much of the string as possible, including instances of the desired target, until it reaches the last instance of the target. So, the whole regex matches the entire string up to and including the last instance of the larget, and then replaces it with the matched (.*) which is everything before the target string.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: JavaScript replace all / with \ in a string? I have a
Possible Duplicate: Replace multiple whitespaces with single whitespace in JavaScript string I have used
Possible Duplicate: How to replace several words in javascript I have a string: var
Possible Duplicate: Replace only first match using preg_replace I have a string as follows:
Possible Duplicate: replace all occurrences in a string I found this question/answer: Use JavaScript
Possible Duplicate: How to replace all points in a string in JavaScript I am
Possible Duplicate: How to replace string in SQLite? I have a table column data
Possible Duplicate: replace all occurrences in a string I have this string: 12-3-02 And
Possible Duplicate: Replace all occurrences of substring in a string - which is more
Possible Duplicate: Replace words in a string, but ignore HTML Is it possible 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.