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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T15:21:57+00:00 2026-06-02T15:21:57+00:00

I have a regex which checks if a string is a number. The format’s

  • 0

I have a regex which checks if a string is a number. The format’s thousand separator is a white space, decimal separator is a dot. After-decimal part is optional.

The issue is that at some point String.matches() function stops working as expected. What worked before, does not work anymore.

For example, JUnit code:

import junit.framework.Assert;
import org.junit.Test;

public class RegExTest {

    @Test
    public void testThousandSeperatorRegex()
    {
        String regEx = "([0-9]{1,3}( [0-9]{3})*(\\.[0-9]+)?|\\.[0-9]+)";
        Assert.assertEquals(true, "1".matches(regEx));
        Assert.assertEquals(true, "10".matches(regEx));
        Assert.assertEquals(true, "100".matches(regEx));
        Assert.assertEquals(true, "1 000".matches(regEx));
        Assert.assertEquals(true, "10 000".matches(regEx));
        Assert.assertEquals(true, "100 000".matches(regEx));
        Assert.assertEquals(true, "1 000 000".matches(regEx));
        Assert.assertEquals(true, "10 000 000".matches(regEx));
        Assert.assertEquals(false, "10000.56".matches(regEx));
        Assert.assertEquals(true, "8 734".matches(regEx));
    }
}

The last line with “8 734” fails. When I replace it with “1 000” it continues to fail. Eventually, the same code at the same run passes in the 4th line of assertions, but fails in the last (the new code is saved!).
But there are times when everything starts working just as expected until.. start failing again. So I suppose that it will be hard to reproduce my issue. Maybe there are something else that I’m doing wrong which I haven’t noticed and thus described, but I tried to make it as plain as possible.
This one confuses me a lot. Does String.matches() has a memory or what?

Could there be something wrong with the regular expression? I’m skipping ^$ as String.matches works on whole string anyway. I have tried java.util.regex and jregex packages, the issue persisted.

I’m using JDK 6u31.

Any ideas appreciated.

UPD: ok, after posting this Q the code started to work and hasn’t fail so far. Maybe it was something with me, but this has bothered me since last week and I have been able to replicate it again and again. I will continue with my piece of code and if it will continue to work I will close this issue. Also I will try to determine what exactly caused the problem.
Meanwhile, if there are someone out there who has encountered the same issue, please share your knowledge. Otherwise, this looks like an issue that can be solved by knowledge, not by debugging.
To defend myself from stupidity I can say I have been programming for many years and this is the 1st ever post in forums :). Until now I was able to solve my problems with debugging, reading docs and searching forums of other Qs.

  • 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-02T15:21:58+00:00Added an answer on June 2, 2026 at 3:21 pm

    OK, so far I haven’t encountered this issue anymore.

    For other who happen to meet this one someday, I can only suggest to clean up the environment that you are working in. This has to do something with corrupted JVM or computer’s memory state.

    Thanks everyone for their contribution.

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

Sidebar

Related Questions

I have a string containing a date which has a lot of format possibilities.
I might have pretty basic question about regex. I have the following regex, which
I have this regex working but now need to allow numbers without the decimal
I have some Regex, it looks like this: string regexForDrop = @^((%27)|'|(\-\-))\s*(d|%64|%44)(r|%72|%52)(o|%6F|%4F)(p|%70|%50)$; It works
I have a regex expression that I'm doing a split against another string and
I have this regex: private static final String SPACE_PATH_REGEX =[a-z|A-Z|0-9|\\/|\\-|\\_|\\+]+; I check if my
I have a string which is formatted like this: $20,$40,$AA,$FF. Basically, hex numbers and
Here is the deal. I have a string which contains a html <a><img /></a>
i have data of thousand records which i read line by line . Each
I have a JSP redemption for XSS attacks, in which it checks if the

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.