top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

What is the difference between an ordinary character and a metacharacter?

+3 votes
428 views

Give an example of each.

posted Feb 19, 2014 by Merry

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote
 
Best answer

The metacharacters in a Java RegEx are:
([{^$|)?*+.
If you want to treat them as ordinary characters you have two options:
1. Escape the metacharacter with a backslash,
2. Enclose the whole string that contains metacharacters within Q and E Q means: "quotes all characters until E", while E ends the quotes.

String test = "I want to replace the . with the ,";
String replaced = test.replaceAll("\.", ",");
System.out.println(replaced);

The output will be:

Output:  I want to replace the , with the ,
answer Feb 23, 2014 by Amit Kumar Pandey
...