List of usage examples for com.google.gwt.regexp.shared RegExp getGlobal
public final boolean getGlobal()
From source file:com.google.collide.shared.util.RegExpUtils.java
License:Open Source License
/** * Returns the number of matches found in a string by a regexp. If the regexp * is not a global regexp this will return a maximum of 1. This does not * setLastIndex(0) automatically, you must do it manually. * * @returns number of matches// w ww .j av a 2 s . c o m */ public static int getNumberOfMatches(RegExp regexp, String input) { if (regexp == null || input == null || input.isEmpty()) { return 0; } // if we don't check here we will loop forever if (!regexp.getGlobal()) { return regexp.test(input) ? 1 : 0; } int matches = 0; for (MatchResult result = regexp.exec(input); result != null && result.getGroup(0).length() != 0; result = regexp.exec(input)) { matches++; } return matches; }