Quoted sequence \Q...\E

Q

What is the quoted sequence to disable pattern metacharacters?

How to write a regular expression to capture the main() method in a Java class like: class ABC { public static void main(String args[]){...} }

✍: FYIcenter.com

A

The quoted sequence is a subpattern where pattern metacharacters are treated literally. A quoted sequence starts with \Q and ends with \E. For example:

\Q\.^*+?[]|(){}\E   - matches \.^*+?[]|(){}

The regular expression to capture the main() method in Java class is:

\Qmain(String args[])\E

\Q...\E   - Quoted sequence to keep () [] as is

Click the button to test this regular expression here online:

2013-01-26, 0👍, 0💬