當前位置: 首頁>>代碼示例>>Java>>正文


Java Matcher.toMatchResult方法代碼示例

本文整理匯總了Java中java.util.regex.Matcher.toMatchResult方法的典型用法代碼示例。如果您正苦於以下問題:Java Matcher.toMatchResult方法的具體用法?Java Matcher.toMatchResult怎麽用?Java Matcher.toMatchResult使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.util.regex.Matcher的用法示例。


在下文中一共展示了Matcher.toMatchResult方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: parseName

import java.util.regex.Matcher; //導入方法依賴的package包/類
/**
 * 根據文件名得到插件名
 *
 * @param fullname
 * @param type
 * @return
 */
public static final String parseName(String fullname, int type) {
    Matcher m = null;
    if (type == INCREMENT_PLUGIN) {
        m = INCREMENT_REGEX.matcher(fullname);
    } else if (type == SINGLE_PLUGIN) {
        m = INCREMENT_SINGLE_REGEX.matcher(fullname);
    } else if (type == MULTI_PLUGIN) {
        m = MULTI_REGEX.matcher(fullname);
    } else {
        m = NORMAL_REGEX.matcher(fullname);
    }
    if (m == null || !m.matches()) {
        return null;
    }
    MatchResult r = m.toMatchResult();
    if (r == null || r.groupCount() != 1) {
        return null;
    }
    return r.group(1);
}
 
開發者ID:wangyupeng1-iri,項目名稱:springreplugin,代碼行數:28,代碼來源:DownloadFileInfo.java

示例2: main

import java.util.regex.Matcher; //導入方法依賴的package包/類
public static void main(String[] args) {
    String string = "Vol. 15 xxx";
    Pattern p = Pattern.compile(".*(\\d+).*");
    Matcher m = p.matcher(string);

    if (m.find()) {
        MatchResult mr = m.toMatchResult();
        String value = mr.group(1);
        System.out.println("found: " + value);
    }

    p = Pattern.compile("\\d+");
    m = p.matcher(string);
    while (m.find()) {
        try {
            String sub = string.substring(m.start(), m.end());
            System.out.println("found 2: " + sub);
        } catch (NumberFormatException e) {
            logger.error(e.getMessage());
        }
    }
}
 
開發者ID:intranda,項目名稱:goobi-viewer-indexer,代碼行數:23,代碼來源:MetadataHelper.java

示例3: apply

import java.util.regex.Matcher; //導入方法依賴的package包/類
@Override
public Result<MatchResult> apply(String input) {
  Matcher matcher = pattern.matcher(input);

  if (matcher.lookingAt()) {
    return new Accept<>(matcher.toMatchResult(), input.substring(matcher.end()));
  } else {
    return new Reject<>(input + " does not match " + matcher.pattern());
  }
}
 
開發者ID:jparsercombinator,項目名稱:jparsercombinator,代碼行數:11,代碼來源:RegexParserCombinator.java

示例4: build

import java.util.regex.Matcher; //導入方法依賴的package包/類
public static final PluginInfo build(File f) {
    Matcher m = REGEX.matcher(f.getName());
    if (m == null || !m.matches()) {
        if (LOG) {
            LogDebug.d(PLUGIN_TAG, "PluginInfo.build: skip, no match1, file=" + f.getAbsolutePath());
        }
        return null;
    }
    MatchResult r = m.toMatchResult();
    if (r == null || r.groupCount() != 4) {
        if (LOG) {
            LogDebug.d(PLUGIN_TAG, "PluginInfo.build: skip, no match2, file=" + f.getAbsolutePath());
        }
        return null;
    }
    String name = r.group(1);
    int low = Integer.parseInt(r.group(2));
    int high = Integer.parseInt(r.group(3));
    int ver = Integer.parseInt(r.group(4));
    String path = f.getPath();
    PluginInfo info = new PluginInfo(name, low, high, ver, TYPE_PN_INSTALLED, DownloadFileInfo.NONE_PLUGIN, path, -1, -1, -1, null);
    if (LOG) {
        LogDebug.d(PLUGIN_TAG, "PluginInfo.build: found plugin, name=" + info.getName()
                + " low=" + info.getLowInterfaceApi() + " high=" + info.getHighInterfaceApi()
                + " ver=" + info.getVersion());
    }
    return info;
}
 
開發者ID:wangyupeng1-iri,項目名稱:springreplugin,代碼行數:29,代碼來源:PluginInfo.java

示例5: newMatchResult

import java.util.regex.Matcher; //導入方法依賴的package包/類
/**
 * Returns a new {@code MatchResult} that corresponds to a successful match. Apache Harmony (used
 * in Android) requires a successful match in order to generate a {@code MatchResult}:
 * http://goo.gl/5VQFmC
 */
private static MatchResult newMatchResult() {
  Matcher matcher = Pattern.compile(".").matcher("X");
  matcher.find();
  return matcher.toMatchResult();
}
 
開發者ID:zugzug90,項目名稱:guava-mock,代碼行數:11,代碼來源:ArbitraryInstances.java

示例6: build

import java.util.regex.Matcher; //導入方法依賴的package包/類
/**
 * 通過文件名和文件類型,構建V5FileInfo對象
 *
 * @param f
 * @param type
 * @return
 */
static final DownloadFileInfo build(File f, int type) {
    Matcher m = null;
    String fullname = f.getName();
    if (type == INCREMENT_PLUGIN) {
        m = INCREMENT_REGEX.matcher(fullname);
    } else if (type == SINGLE_PLUGIN) {
        m = INCREMENT_SINGLE_REGEX.matcher(fullname);
    } else if (type == MULTI_PLUGIN) {
        m = MULTI_REGEX.matcher(fullname);
    } else {
        m = NORMAL_REGEX.matcher(fullname);
    }
    if (m == null || !m.matches()) {
        if (AppConstant.LOG_V5_FILE_SEARCH) {
            if (LOG) {
                LogDebug.d(PLUGIN_TAG, "DownloadFileInfo.build: skip, no match1, type=" + type + " file=" + f.getAbsolutePath());
            }
        }
        return null;
    }
    MatchResult r = m.toMatchResult();
    if (r == null || r.groupCount() != 1) {
        if (AppConstant.LOG_V5_FILE_SEARCH) {
            if (LOG) {
                LogDebug.d(PLUGIN_TAG, "DownloadFileInfo.build: skip, no match2, type=" + type + " file=" + f.getAbsolutePath());
            }
        }
        return null;
    }
    if (!f.exists() || !f.isFile()) {
        if (AppConstant.LOG_V5_FILE_SEARCH) {
            if (LOG) {
                LogDebug.d(PLUGIN_TAG, "DownloadFileInfo.build: nor exist or file, file=" + f.getAbsolutePath());
            }
        }
        return null;
    }
    DownloadFileInfo p = new DownloadFileInfo();
    p.mName = r.group(1);
    p.mFile = f;
    p.mType = type;
    if (LOG) {
        LogDebug.d(PLUGIN_TAG, "DownloadFileInfo.build: found plugin, name=" + p.mName + " file=" + f.getAbsolutePath());
    }
    return p;
}
 
開發者ID:wangyupeng1-iri,項目名稱:springreplugin,代碼行數:54,代碼來源:DownloadFileInfo.java

示例7: evalPluginProcess

import java.util.regex.Matcher; //導入方法依賴的package包/類
static final int evalPluginProcess(String name) {
    int index = IPluginManager.PROCESS_AUTO;

    try {
        if (TextUtils.equals(IPC.getPackageName(), name)) {
            if (LOG) {
                LogDebug.d(PLUGIN_TAG, "plugin process checker: default, index=" + 0);
            }
            return IPluginManager.PROCESS_UI;
        }

        if (!TextUtils.isEmpty(name)) {
            if (name.contains(PluginProcessHost.PROCESS_PLUGIN_SUFFIX2)) {
                String tail = PluginProcessHost.processTail(name);
                return PluginProcessHost.PROCESS_INT_MAP.get(tail);
            }
        }

        Matcher m = PROCESS_NAME_PATTERN.matcher(name);
        if (m == null || !m.matches()) {
            if (LOG) {
                LogDebug.d(PLUGIN_TAG, "plugin process checker: non plugin process in=" + name);
            }
            return IPluginManager.PROCESS_AUTO;
        }

        MatchResult r = m.toMatchResult();
        if (r == null || r.groupCount() != 2) {
            if (LOG) {
                LogDebug.d(PLUGIN_TAG, "plugin process checker: no group in=" + name);
            }
            return IPluginManager.PROCESS_AUTO;
        }

        String pr = r.group(1);
        if (!TextUtils.equals(IPC.getPackageName(), pr)) {
            if (LOG) {
                LogDebug.d(PLUGIN_TAG, "plugin process checker: package name not match in=" + name);
            }
            return IPluginManager.PROCESS_AUTO;
        }

        String str = r.group(2);
        index = Integer.parseInt(str);
        if (LOG) {
            LogDebug.d(PLUGIN_TAG, "plugin process checker: index=" + index);
        }
    } catch (Throwable e) {
        if (LOG) {
            LogDebug.d(PLUGIN_TAG, e.getMessage(), e);
        }
    }

    return index;
}
 
開發者ID:wangyupeng1-iri,項目名稱:springreplugin,代碼行數:56,代碼來源:PluginManager.java

示例8: MatchResultHolder

import java.util.regex.Matcher; //導入方法依賴的package包/類
MatchResultHolder(Matcher m) {
    this(m.toMatchResult());
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:4,代碼來源:PatternStreamTest.java


注:本文中的java.util.regex.Matcher.toMatchResult方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。