0

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:

Sample:

    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 
Toni Pujol
  • 13
  • 2
  • Oops, maybe I chose not the best question for a dupe source. But the question is offtopic anyway. Note that `-` in `_-~` creates a range. Besides, look at [this demo](https://ideone.com/xyF4Vz). The regex you got is `\Q?.[A-Za-z0-9.@_-~#]**\E`. Definitely, it is wrong. Please edit your question to say what you actually are trying to do so that it could be reopened. Posts asking to explain a pattern are considered off-topic. – Wiktor Stribiżew Jan 14 '16 at 15:27
  • 3
    Because your pattern does not match the input. – Wiktor Stribiżew Jan 14 '16 at 15:29
  • I opened the question since I think it can now be answered. There are several issues here. – Wiktor Stribiżew Jan 14 '16 at 15:48
  • 1
    Why not simply "^Is your name .*\\?$" – Andrea Bergia Jan 14 '16 at 15:54
  • Please see my [updated demo](https://ideone.com/9JFiEp) - does it work as you expect? – Wiktor Stribiżew Jan 14 '16 at 16:34

0 Answers0