Java examples for Language Basics:String
Notice the space character between the numeric sequence.
public class Main { public static void main(String[] args) throws Exception { String str = ""; str = "I love Java 8!"; boolean result = str.matches("I love .*[ 0-9]!"); System.out.println(result); /* w ww . j a v a2 s . c o m*/ // The following String also matches. str = "I love Jython 2.5.4!"; result = str.matches("I love .*[ 0-9]!"); System.out.println(result); } }