本文整理匯總了Java中com.google.gwt.regexp.shared.RegExp.exec方法的典型用法代碼示例。如果您正苦於以下問題:Java RegExp.exec方法的具體用法?Java RegExp.exec怎麽用?Java RegExp.exec使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.google.gwt.regexp.shared.RegExp
的用法示例。
在下文中一共展示了RegExp.exec方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: showPresenter
import com.google.gwt.regexp.shared.RegExp; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
protected void showPresenter(String token) {
Presenter<? extends View<? extends Element>> matchingPresenter = null;
MatchResult matchResult = null;
for (Presenter<? extends View<? extends Element>> presenter : presenters) {
RegExp regExp = presenter.getTokenRegExp();
if (regExp == null) {
continue;
}
matchResult = regExp.exec(token);
if (matchResult != null) {
matchingPresenter = presenter;
break;
}
}
if (matchingPresenter == null) {
LOG.warning("No presenter found for token \"" + token + "\".");
return;
}
final String[] groups = new String[matchResult.getGroupCount()];
for (int i = 0; i < matchResult.getGroupCount(); i++) {
groups[i] = matchResult.getGroup(i);
}
setCurrentPresenter((Presenter<? extends View<Element>>) matchingPresenter, groups);
}
示例2: parseTag
import com.google.gwt.regexp.shared.RegExp; //導入方法依賴的package包/類
public static String[] parseTag(final String tag) {
String[] result = null;
if (tag != null) {
RegExp regExp = RegExp.compile(IMAGE_TAG_PATTERN);
MatchResult matcher = regExp.exec(tag);
boolean matchFound = matcher != null;
if (matchFound) {
result = new String[matcher.getGroupCount()];
// Get all groups for this match
for (int i = 0; i < matcher.getGroupCount(); i++) {
String groupStr = matcher.getGroup(i);
result[i] = groupStr;
}
}
}
return result;
}
示例3: getHash
import com.google.gwt.regexp.shared.RegExp; //導入方法依賴的package包/類
/**
* Gets the true hash value. Cannot use location.hash directly due to bug
* in Firefox where location.hash will always be decoded.
*
* @param iframe
* @return
*/
public String getHash(IFrameElement iframe) {
RegExp re = RegExp.compile("#(.*)$");
String href = location.getHref();
if(iframe != null) {
href = getIFrameUrl(iframe);
}
MatchResult result = re.exec(href);
return result != null && result.getGroupCount() > 1 ? result.getGroup(1) : "";
}
示例4: extractParameters
import com.google.gwt.regexp.shared.RegExp; //導入方法依賴的package包/類
/**
* Given a route, and a URL fragment that it matches, return the array of
* extracted decoded parameters. Empty or unmatched parameters will be
* treated as `null` to normalize cross-browser behavior.
*
* @param route
* @param fragment
* @return
*/
public static String[] extractParameters(RegExp route, String fragment) {
MatchResult matchResult = route.exec(fragment);
int groupCount = matchResult.getGroupCount() - 1;
if(groupCount < 0)
groupCount = 0;
List<String> params = new ArrayList<String>();
for (int i = 0; i < groupCount; i++) {
String param = matchResult.getGroup(i + 1);
if (param != null && !param.isEmpty()) {
// Don't decode the search params.
if(i == groupCount - 1) {
params.add(param);
} else {
params.add(decodeURIComponent(param));
}
}
}
return params.toArray(new String[params.size()]);
}
示例5: replace
import com.google.gwt.regexp.shared.RegExp; //導入方法依賴的package包/類
/**
* Execute a regular expression and invoke a callback for each match
* occurance. The return value of the callback is substituted for the match.
*
* @param expression a compiled regular expression
* @param text a String on which to perform replacement
* @param replacer a callback that maps matched strings into new values
*/
private static String replace(RegExp expression, String text,
RegExpReplacer replacer) {
expression.setLastIndex(0);
MatchResult mresult = expression.exec(text);
StringBuffer toReturn = new StringBuffer();
int lastIndex = 0;
while (mresult != null) {
toReturn.append(text.substring(lastIndex, mresult.getIndex()));
toReturn.append(replacer.replace(mresult.getGroup(0)));
lastIndex = mresult.getIndex() + 1;
mresult = expression.exec(text);
}
toReturn.append(text.substring(lastIndex));
return toReturn.toString();
}
示例6: transformResponse
import com.google.gwt.regexp.shared.RegExp; //導入方法依賴的package包/類
@Override
protected void transformResponse(DSResponse response, DSRequest request, Object data) {
if (RestConfig.isStatusOk(response)) {
for (Record record : response.getData()) {
String path = record.getAttribute(FIELD_PATH);
RegExp pathRegExp = RegExp.compile("(.*/)?(.*)/$");
MatchResult mr = pathRegExp.exec(path);
String parent = mr.getGroup(1);
String name = mr.getGroup(2);
// System.out.println("## ITRDS.path: " + path);
// System.out.println("## ITRDS.parent: " + parent);
// System.out.println("## ITRDS.name: " + name);
record.setAttribute(FIELD_NAME, name);
record.setAttribute(FIELD_PARENT, parent);
}
}
super.transformResponse(response, request, data);
}
示例7: processChange
import com.google.gwt.regexp.shared.RegExp; //導入方法依賴的package包/類
@Override
public TextChange processChange(final TextChange change, ReadOnlyDocument document) {
final RegExp regex = RegExp.compile("^\n(\\s*)\\*\\s*$");
final MatchResult matchResult = regex.exec(change.getNewText());
// either must be on the first line or be just after a line break (regexp)
if (matchResult != null) {
final String line = document.getLineContent(change.getFrom().getLine());
// matches a line containing only whitespaces followed by either /** or /* and then optionally
// whitespaces again
if (!line.matches("^\\s*\\/\\*\\*?\\s*$")) {
return null;
}
final String whitespaces = matchResult.getGroup(1);
final String modifiedInsert = "\n" + whitespaces + "* \n" + whitespaces + "*/";
return new TextChange.Builder()
.from(change.getFrom())
.to(change.getFrom())
.insert(modifiedInsert)
.build();
} else {
return null;
}
}
示例8: getNumberOfMatches
import com.google.gwt.regexp.shared.RegExp; //導入方法依賴的package包/類
/**
* 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
*/
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;
}
示例9: fuzzyMatch
import com.google.gwt.regexp.shared.RegExp; //導入方法依賴的package包/類
public List<Match> fuzzyMatch(String word, String wordToMatch, boolean substringMatch) {
RegExp regExp = regExpCache.get(word);
if (regExp == null) {
regExp = convertWordToRegExp(word);
regExpCache.put(word, regExp);
}
MatchResult matchResult = regExp.exec(wordToMatch);
if (matchResult != null) {
return Collections.singletonList(
new Match(
matchResult.getIndex(), matchResult.getIndex() + matchResult.getGroup(0).length()));
}
if (substringMatch) {
return FUZZY_SEPARATE.match(word, wordToMatch);
} else {
return FUZZY_CONTIGUOUS.match(word, wordToMatch);
}
}
示例10: isValidDomainAddress
import com.google.gwt.regexp.shared.RegExp; //導入方法依賴的package包/類
private static boolean isValidDomainAddress(final String domain, final RegExp pattern) {
// if we have a trailing dot the domain part we have an invalid email address.
// the regular expression match would take care of this, but IDN.toASCII drops the trailing '.'
if (domain.endsWith(".")) {
return false;
}
final MatchResult matcher = pattern.exec(domain);
if (matcher == null) {
return false;
}
String asciiString;
try {
asciiString = IDN.toASCII(domain);
} catch (final IllegalArgumentException e) {
return false;
}
return asciiString.length() <= MAX_DOMAIN_PART_LENGTH;
}
示例11: getLinkHost
import com.google.gwt.regexp.shared.RegExp; //導入方法依賴的package包/類
/**
* Returns the domain of a link, for displaying next to link. Examples:
* http://ourbugsoftware/1239123 -> [ourbugsoftware/]
* http://testcases.example/mytest/1234 -> [testcases.example/]
*
* If the protocol isn't whitelisted (see PROTOCOL_WHITELIST) or the URL can't be parsed,
* this will return null.
*
* @param link the full URL
* @return the host of the URL. Null if protocol isn't in PROTOCOL_WHITELIST or URL can't be
* parsed.
*/
public static String getLinkHost(String link) {
if (link != null) {
// It doesn't seem as if java.net.URL is GWT-friendly. Thus... GWT regular expressions!
RegExp regExp = RegExp.compile("(\\w+?)://([\\-\\.\\w]+?)/.*");
// toLowerCase is okay because nothing we're interested in is case sensitive.
MatchResult result = regExp.exec(link.toLowerCase());
if (result != null) {
String protocol = result.getGroup(1);
String host = result.getGroup(2);
if (PROTOCOL_WHITELIST.contains(protocol)) {
return "[" + host + "/]";
}
}
}
return null;
}
示例12: isImageDataUri
import com.google.gwt.regexp.shared.RegExp; //導入方法依賴的package包/類
private static boolean isImageDataUri(String schemeSpecificPart)
{
RegExp regExp = RegExp.compile("([^,]*?)(;base64)?,(.*)", "mi");
MatchResult result = regExp.exec(schemeSpecificPart);
if (result != null )
{
String mimeType = result.getGroup(DATA_URI.TYPE.ordinal());
for( int i = 0; i < ALLOWED_IMAGE_TYPES.length; i++ )
{
if( ALLOWED_IMAGE_TYPES[i].equals(mimeType) )
{
return true;
}
}
}
return false;
}
示例13: calculateEnabled
import com.google.gwt.regexp.shared.RegExp; //導入方法依賴的package包/類
public boolean calculateEnabled(String value, String flag)
{
boolean result = false;
if (value != null && RegExp.compile(FLAGS_PATTERN).test(value))
{
MatchResult match;
RegExp flagsPattern = RegExp.compile(FLAGS_PATTERN);
if ((match = flagsPattern.exec(value)) != null)
{
String on = match.getGroup(1);
String off = match.getGroup(3);
if (off != null && off.contains(flag))
result = false;
else if (on != null && on.contains(flag))
result = true;
else
result = false;
}
}
else
result = false;
return result;
}
示例14: parse
import com.google.gwt.regexp.shared.RegExp; //導入方法依賴的package包/類
private void parse(final List<Chip> chips, final String text, final Collection<Filter> filters, final AsyncCallback<Parser.Results> callback) {
if (text.isEmpty()) {
callback.onSuccess(new Parser.Results(text, chips));
} else {
for (RegExp regExp: sRegExps) {
final MatchResult r = regExp.exec(text);
if (r == null) continue;
for (Filter filter: filters) {
if (filter.getCommand().equals(r.getGroup(1))) {
filter.validate(r.getGroup(2), new AsyncCallback<Chip>() {
@Override
public void onFailure(Throwable caught) {
callback.onSuccess(new Parser.Results(text, chips));
}
@Override
public void onSuccess(Chip result) {
if (result == null) {
callback.onSuccess(new Parser.Results(text, chips));
} else {
chips.add(result);
if (r.getGroupCount() > 3) {
parse(chips, r.getGroup(3).trim(), filters, callback);
} else {
callback.onSuccess(new Parser.Results("", chips));
}
}
}
});
return;
}
}
}
callback.onSuccess(new Parser.Results(text, chips));
}
}
示例15: getSearch
import com.google.gwt.regexp.shared.RegExp; //導入方法依賴的package包/類
/**
* In IE6, the hash fragment and search params are incorrect if the
* fragment contains `?`.
*
* @return
*/
protected String getSearch() {
RegExp re = RegExp.compile("\\?.+");
String href = location.getHref().replaceAll("#.*", "");
MatchResult result = re.exec(href);
return result != null ? result.getGroup(0) : "";
}