Home
Categories
Dictionary
Download
Project Details
Changes Log
FAQ
License

util.regex


The regex package contains additional classes which work with the Java regex package.

RegexCollection

Main Article: RegexCollection

The RegexCollection class allows to specify a list of regex patterns and match a CharSequence against all the patterns. It simplifies the usage of several regex expressions against the same input.

This class encapsulates a lot of methods of the Matcher class.

Example

The following example shows a simple usage of the class:
   RegexCollection collection = new RegexCollection();
   collection.addPattern("number", "\\d+");
   collection.addPattern("letters", "[A-Za-z]+");
      
   RegexMatcher matcher = collection.matcher("156");
   String name = matcher.getPatternName(); // return "number"
   boolean matches = matcher.matches(); // return true

   matcher = collection.matcher("Slayer");
   name = matcher.getPatternName(); // return "letters"
   matches = matcher.matches(); // return true

   matcher = collection.matcher("1349 band");
   name = matcher.getPatternName(); // return "letters"
   matches = matcher.matches(); // return false      

Categories: Packages | Util

Copyright 2006-2024 Herve Girod. All Rights Reserved. Documentation and source under the LGPL v2 and Apache 2.0 licences