Get Programming Language Keywords By Using Regular Expression in Java

We can use regular expression to get all Java keywords in a program. The key is using word boundary correctly. For example, given “static staticField”, the first word should be recognized as a keyword but the second should not.

Read more

Backreferences in Java Regular Expressions

Backreferences in Java Regular Expressions is another important feature provided by Java.

To understand backreferences, we need to understand group first. Group in regular expression means treating multiple characters as a single unit. They are created by placing the characters to be grouped inside a set of parentheses – ”()”. Each set of parentheses corresponds to a group.

Read more

Regular Expression: exclude a word/string

If you want to exclude a certain word/string in a search pattern, a good way to do this is regular expression assertion function. It is indispensable if you want to match something not followed by something else. A Simple Example String str = "programcreek"; Pattern p = Pattern.compile(".*program(?=creek).*"); Matcher m = p.matcher(str);   if(m.matches()){ System.out.println("Match!"); … Read more