fork download
  1. /*
  2. Date : 07 May 2014
  3. */
  4.  
  5. import java.util.Scanner;
  6. import java.util.regex.Pattern;
  7. import java.util.regex.Matcher;
  8.  
  9. public class Main{
  10. public static void main(String[] args){
  11.  
  12. //Declaring all required variables
  13. String inputString, inputRegex, searchText;
  14. int matchCount = 0;
  15.  
  16. //create a new scanner object
  17. Scanner scannerObj = new Scanner(System.in);
  18.  
  19. //get the inputString
  20. inputString = scannerObj.nextLine();
  21.  
  22. searchText = inputString;
  23.  
  24. System.out.println("Read string : " + inputString);
  25.  
  26. //apply pattern to inputString
  27. System.out.println(searchText.matches("\\Q<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\\E"));
  28. System.out.println(searchText.matches(Pattern.quote("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>")));
  29.  
  30. System.out.println(searchText.replaceAll("\\Q<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\\E", "XXX"));
  31. System.out.println(searchText.replaceAll(Pattern.quote("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>"), "XXX"));
  32. }
  33. }
Success #stdin #stdout 0.1s 380608KB
stdin
<?xml version="1.0" encoding="UTF-8" standalone="no"?>

stdout
Read string : <?xml version="1.0" encoding="UTF-8" standalone="no"?>
true
true
XXX
XXX