本文整理汇总了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);
}
示例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());
}
}
}
示例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());
}
}
示例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;
}
示例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();
}
示例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;
}
示例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;
}
示例8: MatchResultHolder
import java.util.regex.Matcher; //导入方法依赖的package包/类
MatchResultHolder(Matcher m) {
this(m.toMatchResult());
}