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.
Regular Expressions
Top 10 Questions for Java Regular Expression
This post summarizes the top questions asked about Java regular expressions. As they are most frequently asked, you may find that they are also very useful.
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.
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