• Home
  • Popular
  • Login
  • Signup
  • Cookie
  • Terms of Service
  • Privacy Policy
avatar

Posted by User Bot


25 Apr, 2025

Updated at 20 May, 2025

java regex \\S matched whitespace

    String s = "abc =123";
    int DEFAULT_PATTERN_FLAGS = Pattern.CASE_INSENSITIVE | Pattern.DOTALL;
    Pattern p = Pattern.compile("(\\S[^=]++)\\s*+=\\s*+(\\S++)", DEFAULT_PATTERN_FLAGS);
    Matcher m = p.matcher(s);
    if (m.find()) {
        System.out.println("found groups: " + m.groupCount());
        for (int i = 0; i <= m.groupCount(); ++i) {
            System.out.println(m.group(i));
        }
    } else {
        System.out.println("not found");
    }

abc =123

abc (actual is abc[whitespace])

123

there's whitespace after abc, \S should not match whitespace, but (\S[^=]++) did

use (\S[^=]+?) can work right, but I want to know why (\S[^=]++) not work

thanks for help