Pattern.CANON_EQ : Pattern « java.util.regex « Java by API






Pattern.CANON_EQ

/*
gal matches input gal
gal matches input e?gal
gal does not match input e?gal
gal does not match input e'gal
gal does not match input egal
 * */
import java.util.regex.Pattern;

/**
 * CanonEqDemo - show use of Pattern.CANON_EQ, by comparing varous ways of
 * entering the Spanish word for "equal" and see if they are considered equal by
 * the RE-matching engine.
 * 
 * @version $Id: CanonEqDemo.java,v 1.3 2004/03/21 20:06:20 ian Exp $
 */
public class MainClass {
  public static void main(String[] args) {
    String pattStr = "\u00e9gal"; // gal
    String[] input = { "\u00e9gal", // gal - this one had better match :-)
        "e\u0301gal", // e + "Combining acute accent"
        "e\u02cagal", // e + "modifier letter acute accent"
        "e'gal", // e + single quote
        "e\u00b4gal", // e + Latin-1 "acute"
    };
    Pattern pattern = Pattern.compile(pattStr, Pattern.CANON_EQ);
    for (int i = 0; i < input.length; i++) {
      if (pattern.matcher(input[i]).matches()) {
        System.out.println(pattStr + " matches input " + input[i]);
      } else {
        System.out.println(pattStr + " does not match input " + input[i]);
      }
    }
  }
}

           
       








Related examples in the same category

1.Pattern.CASE_INSENSITIVE
2.Pattern: compile('d.*ian')
3.Pattern: compile('(\\w+)\\s(\\d+)')
4.Pattern: compile('e.+?d')
5.Pattern: compile('[a-z]+')
6.Pattern: compile(String text)
7.Pattern: matcher(String text)
8.Pattern: split(String str)