-4
public class RegularExpressionDemo2 {

    public static void main(String[] args) {
        Pattern p = Pattern.compile("\\.");
        Matcher m = p.matcher("a1b7 @z#");
        while (m.find()) {
            System.out.println(m.start() + "-------" + m.group());
        }
    }
}

From the docs, it says the . symbol prints any character then How come the above program doesn't print any thing.

kittu
  • 6,662
  • 21
  • 91
  • 185

1 Answers1

1

You double-escaped the dot.

This means you are matching a literal dot, not a wildcard for any character.

Your input does not contain one, hence nothing gets printed.

Change the Pattern to ".".

Mena
  • 47,782
  • 11
  • 87
  • 106