Java – find words that contain only the given characters: regex
•
Java
I have a set of words For example,
abc,adb,acb,cab,abcc,abk,bacc
If I want to find only
So, what I need is
abc,bacc
I need to find it using regular expressions Can someone help me
Solution
The following regular expression will only find all your words, including ABC characters
Pattern regex = Pattern.compile("\\b[abc]+\\b"); Matcher regexMatcher = regex.matcher(subjectString); while (regexMatcher.find()) { // matched text: regexMatcher.group() // match start: regexMatcher.start() // match end: regexMatcher.end() }
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码