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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T17:06:33+00:00 2026-05-30T17:06:33+00:00

My goal is to match the first 0 and everything after that zero in

  • 0

My goal is to match the first 0 and everything after that zero in a decimal value. If the first decimal place is a zero then I want to match the decimal too. If there is no decimal then capture nothing.

Here are some examples of what I want:

180.570123 // should capture the "0123" on the end
180.570    // should capture the "0" on the end
180.0123   // should capture the ".0123" on the end
180.0      // should capture the ".0" on the end
180123     // should capture nothing
180        // should capture nothing

If the first decimal place is a 0 then making the match is easy:

(\.0.*)

My problem is matching when the first decimal place is not a 0. I believe positive lookbehind will fix this issue, but I am not able to get it to work correctly. Here is one regex I have tried:

(?<=^.*\..*)0.*

This regex will eventually be used in Java.

UPDATE:

I am going to use this regex to get rid of numbers and possibly a decimal point on the end of a string using Java’s replaceAll method. I will do this by replacing the capture group with an empty string. Here is a better example of what I want.

String case1 = "180.570123";
String case2 = "180.570";
String case3 = "180.0123";
String case4 = "180.0";
String case5 = "180123";
String case6 = "180";

String result = null;

result = case1.replaceAll( "THE REGEX I NEED", "" );
System.out.println( result ); // should print 180.57

result = case2.replaceAll( "THE REGEX I NEED", "" );
System.out.println( result ); // should print 180.57

result = case3.replaceAll( "THE REGEX I NEED", "" );
System.out.println( result ); // should print 180

result = case4.replaceAll( "THE REGEX I NEED", "" );
System.out.println( result ); // should print 180

result = case5.replaceAll( "THE REGEX I NEED", "" );
System.out.println( result ); // should print 180123

result = case6.replaceAll( "THE REGEX I NEED", "" );
System.out.println( result ); // should print 180

Also, I am testing these regexs at http://gskinner.com/RegExr/

  • 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-30T17:06:35+00:00Added an answer on May 30, 2026 at 5:06 pm

    You can use this expression:

    \.[1-9]*(0\d*)
    

    And what you want will be in the first capturing group. (Except the decimal point.)

    If you want to capture the decimal point too, you can use:

    (?:\.[1-9]+|(?=\.))(\.?0\d*)
    

    Example (online):

    Pattern p = Pattern.compile("(?:\\.[1-9]+|(?=\\.))(\\.?0\\d*)");
    
    String[] strs = {"180.570123", "180.570", "180.0123", "180.0", "180123", "180", "180.2030405"};
    
    for (String s : strs) {
        Matcher m = p.matcher(s);
        System.out.printf("%-12s: Match: %s%n", s,
            m.find() ? m.group(1) : "n/a");
    }
    

    Output:

    180.570123  : Match: 0123
    180.570     : Match: 0
    180.0123    : Match: .0123
    180.0       : Match: .0
    180123      : Match: n/a
    180         : Match: n/a
    180.2030405 : Match: 030405
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First off, I want to say there is no use case for this. The
I want to only select elements that match class X and don't have any
Goal is to make a dialog that appears on menu_key pressed, but it keeps
Goal: Produce an Excel document with information from 3 associated models that is similar
My Basic Goal A Rails app that can load new content via Ajax while
I want to change the format of this array to match another one. One
I'm looking for assistance creating a pattern match to ingest emails. The end goal
I need to match complete dynamic URL to set-up as a goal in Google
I wrote some jQuery code in an external file, with the goal to match
The goal: I want to convert a number from the format 10.234,56 to 10234.56

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.