Tag: Metacharacter

How to force one or more metacharacters to be treated as ordinary characters in a Java Regular Expression (RegEx)

When using RegEx in Java you might face the need of treating one or more metacharacters as ordinary characters. As a reminder 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.

Read more...