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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T12:37:05+00:00 2026-05-31T12:37:05+00:00

I want to remove all occurrences of substring = . in a string except

  • 0

I want to remove all occurrences of substring = . in a string except the last one.

E.G:

1.2.3.4

should become:

123.4
  • 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-31T12:37:07+00:00Added an answer on May 31, 2026 at 12:37 pm

    2-liner:

    function removeAllButLast(string, token) {
        /* Requires STRING not contain TOKEN */
        var parts = string.split(token);
        return parts.slice(0,-1).join('') + token + parts.slice(-1)
    }
    

    Alternative version without the requirement on the string argument:

    function removeAllButLast(string, token) {
        var parts = string.split(token);
        if (parts[1]===undefined)
            return string;
        else
            return parts.slice(0,-1).join('') + token + parts.slice(-1)
    }
    

    Demo:

    > removeAllButLast('a.b.c.d', '.')
    "abc.d"
    

    The following one-liner is a regular expression that takes advantage of the fact that the * character is greedy, and that replace will leave the string alone if no match is found. It works by matching [longest string including dots][dot] and leaving [rest of string], and if a match is found it strips all ‘.’s from it:

    'a.b.c.d'.replace(/(.*)\./, x => x.replace(/\./g,'')+'.')
    

    (If your string contains newlines, you will have to use [.\n] rather than naked .s)

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

Sidebar

Related Questions

I want to take a string and remove all occurrences of characters within square
I want to remove all special characters from a string. Allowed characters are A-Z
I want to remove all non-alphanumeric and space characters from a string. So I
I want to remove all stored revision info, except for the most up to
I want to remove all tags except the img tag, $words = strip_tags($words, '<img>');
I want to remove all the unpartnered or unpaired parenthesises from a string. exampleStr
I want to remove all rows of my table except the header. This is
i'v got such string <>1 <>2 <>3 i want remove all '<>' and symbols
i want remove all \n for JSP page output. i think i should be
I want to remove all the whitespace i..e tabs/spaces/newline chars. T = {xmlelement,presence, [{xml:lang,en}],

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.