java - Regular Expression program from Predefined character classes -


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 docs, says . symbol prints character how come above program doesn't print thing.

you double-escaped dot.

this means matching literal dot, not wildcard character.

your input not contain one, hence nothing gets printed.

change pattern ".".


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -