Why does this regular expression not run?


Please briefly explain why you feel this question should be reported .

Report Cancel

I have some texts like this “Is your name #1 ?” where #1 can be replaced by any thing. By example “Is your name R2D2 and are you a robot ?” must match.

I have tryed to make a Pattern.quote of the first text and then I replace #1 by “[A-Za-z0-9.@_-~#]*” but not run:


    System.out.println("?.*".matches(Pattern.quote("?.*"))); // true
    System.out.println("hola".matches("[A-Za-z0-9.@_-~#]*")); // true
    System.out.println("?hola.*".matches(Pattern.quote("?.#1*").replaceAll("#1", "[A-Za-z0-9.@_-~#]*"))); // it says FALSE 
0 Answer 15 views 0