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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:53:07+00:00 2026-06-17T16:53:07+00:00

Code: static short state = 0; static int td_number = 0; public static void

  • 0

Code:

static short state = 0;
static int td_number = 0;

public static void main(String[] args) {

final Pattern p = Pattern.compile("^[\\s]*?\\d+\\.\\d+[\\s]*?");
final short TD_ENTRY = 0;
final short NO_ENTRY = 1;

HTMLEditorKit.ParserCallback callback = new HTMLEditorKit.ParserCallback() {
    public void handleText(char[] data, int pos) {
    switch (state) {
    case NO_ENTRY:
        break;
    case TD_ENTRY: {
        // We are in the right table column
        // Create string from char array
        String s = new String(data);
        Matcher m = p.matcher(s);
        boolean b = m.matches();
        // Check if data information has correct format (0.0)
        if (b) {

        }
    }
        break;
    default:
        break;
    }
    state = NO_ENTRY;
    }

    public void handleStartTag(HTML.Tag tag, MutableAttributeSet set, int pos) {
    if (tag == HTML.Tag.TD) {
      //[...]
    }
    }
};

Reader reader = new StringReader(html);
try {
    new ParserDelegator().parse(reader, callback, false);
} catch (IOException e) {
}
}

I am trying to parse HTML with Regular Expressions. The program reads the content of td tags within an html table. The content in the table cell should fit a special pattern defined in Pattern p.

The main problem is now that the regex pattern does not match for cell content like this ” 0.1″.
But if I define the String s manually with the value (” 0.1″) in the code the pattern matches.

Furthermore if I copy the content of char[] data in debug mode and define s with this copied content the pattern does also not fit although it looks the same like the manually defined value from above.

Is it possible to find out which whitespace characters are really read?

It seems that the whitespace is not always a whitespace and therefore does not match with regex class [\s]. Is this possible?

EDIT:

Thanks for answers. It was really a whitespace character (\xA0) which was not recognized by \s regex class.

For all of you which downvote (really frustrating) my question simply missunderstood me. Maybe the problem was really the sentence “I want to parse HTML with regex” but in fact I simply have content from a HTML table cell with unknown whitespace characters ;-).

I think I had got the same problems with a library like jsoup.

  • 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-17T16:53:08+00:00Added an answer on June 17, 2026 at 4:53 pm

    In Java regexes, the non-breaking space character (NBSP, U+00A0) is traditionally not treated as whitespace for the purpose of matching \s. If that’s what’s causing your problem, you just need to add it to your existing whitespace class:

    "^[\\s\\xA0]*\\d+\\.\\d+[\\s\\xA0]*$"
    

    There are other Unicode whitespace characters that aren’t matched by \s, but none of them are anywhere as common as the NBSP.

    Alternatively, if you’re running Java 7+ you can specify UNICODE_CHARACTER_CLASS mode and go on using \s.

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

Sidebar

Related Questions

I have some code static void Main(string[] args) { int j = 0; for
Here is my code : public static void main(String[] args) { // System.setProperty( //
I've got really simple code: static void Main(string[] args) { var task = Task.Factory.StartNew(GetInt);
here is the code public static final String DATE_TIME_FORMAT = yyyy-MM-dd kk:mm:ss; public static
First code : public static int pitagoras(int a, int b) { return (int) Math.sqrt(a*a
I think I need a utility method like this: public static short bitValue(int intNum,
Code static void MyClass::ThreadEntryStatic() { //... } void MyClass::Begin() { CreateThread(..,ThreadEntryStatic,..); } In which
this is my code: static { Security.addProvider(new BouncyCastleProvider()); } ... final Cipher sifra =
Today I came across this question: you have a code static int counter =
I have a code: static short Sum(short a, short b) { return a +

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.