本文整理汇总了Java中java.util.regex.Matcher.group方法的典型用法代码示例。如果您正苦于以下问题:Java Matcher.group方法的具体用法?Java Matcher.group怎么用?Java Matcher.group使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.regex.Matcher
的用法示例。
在下文中一共展示了Matcher.group方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getTransferSize
import java.util.regex.Matcher; //导入方法依赖的package包/类
private void getTransferSize() {
lastTransSize = -1;
/**
* If it's a start of data transfer response, let's try to extract
* the size from the response string. Usually it looks like that:
*
* 150 Opening BINARY mode data connection for foo (6701 bytes).
*/
String response = getLastResponseString();
if (transPat == null) {
transPat = Pattern.compile("150 Opening .*\\((\\d+) bytes\\).");
}
Matcher m = transPat.matcher(response);
if (m.find()) {
String s = m.group(1);
lastTransSize = Long.parseLong(s);
}
}
示例2: getJavaFileNameFromSource
import java.util.regex.Matcher; //导入方法依赖的package包/类
/**
* Extracts the Java file name from the class declaration.
* This method is intended for simple files and uses regular expressions,
* so comments matching the pattern can make the method fail.
*/
static String getJavaFileNameFromSource(String source) {
String packageName = null;
Matcher matcher = modulePattern.matcher(source);
if (matcher.find())
return "module-info.java";
matcher = packagePattern.matcher(source);
if (matcher.find())
packageName = matcher.group(1).replace(".", "/");
matcher = classPattern.matcher(source);
if (matcher.find()) {
String className = matcher.group(1) + ".java";
return (packageName == null) ? className : packageName + "/" + className;
} else if (packageName != null) {
return packageName + "/package-info.java";
} else {
throw new Error("Could not extract the java class " +
"name from the provided source");
}
}
示例3: matchStrings
import java.util.regex.Matcher; //导入方法依赖的package包/类
/**
* Main entry point.
* @return {@code true} if the string matches against the pattern, or {@code false} otherwise.
*/
public boolean matchStrings(String str, Map<String, String> uriTemplateVariables) {
Matcher matcher = this.pattern.matcher(str);
if (matcher.matches()) {
if (uriTemplateVariables != null) {
// SPR-8455
if (this.variableNames.size() != matcher.groupCount()) {
throw new IllegalArgumentException("The number of capturing groups in the pattern segment " +
this.pattern + " does not match the number of URI template variables it defines, " +
"which can occur if capturing groups are used in a URI template regex. " +
"Use non-capturing groups instead.");
}
for (int i = 1; i <= matcher.groupCount(); i++) {
String name = this.variableNames.get(i - 1);
String value = matcher.group(i);
uriTemplateVariables.put(name, value);
}
}
return true;
}
else {
return false;
}
}
示例4: parse
import java.util.regex.Matcher; //导入方法依赖的package包/类
private void parse() {
Matcher matcher = TWO_NUMBERS_PATTERN.matcher(input);
if (matcher.matches()) {
linkingNumber = Integer.parseInt(matcher.group(1));
sequenceNumber = Integer.parseInt(matcher.group(2));
fieldLinkTypeChar = matcher.group(3);
} else {
matcher = ONE_NUMBER_PATTERN.matcher(input);
if (matcher.matches()) {
linkingNumber = Integer.parseInt(matcher.group(1));
fieldLinkTypeChar = matcher.group(2);
}
}
if (fieldLinkTypeChar != null)
fieldLinkType = LinkType.byCode(fieldLinkTypeChar);
}
示例5: getGID
import java.util.regex.Matcher; //导入方法依赖的package包/类
@Override
public String getGID(URL url) throws MalformedURLException {
Pattern p = Pattern.compile("^https?://[wm.]*dribbble\\.com/([a-zA-Z0-9]+).*$");
Matcher m = p.matcher(url.toExternalForm());
if (m.matches()) {
return m.group(1);
}
throw new MalformedURLException("Expected dribbble.com URL format: " +
"dribbble.com/albumid - got " + url + "instead");
}
示例6: makeSingleEvent
import java.util.regex.Matcher; //导入方法依赖的package包/类
public Event makeSingleEvent(final String line, final MajorEvent ev) {
final Matcher m = SIMPLE_CSV_PATTERN.matcher(line);
if (m.find()) {
final String rawYear = m.group(1);
final LocalDate raceDay = makeRaceDay(rawYear, ev);
final String winner = m.group(2);
final Double odds = makeOdds(m.group(3));
// System.out.println(winner + " won " + ev + " on " + raceDay + " at odds " + (odds == null ? " N/A " : odds));
return makeEvent(ev, raceDay, winner, odds);
} else {
throw new IllegalArgumentException(line + " does not match, and it should");
}
}
示例7: readHostFile
import java.util.regex.Matcher; //导入方法依赖的package包/类
/**
* TODO
* 读取原始Host文件
*/
public static List<Host> readHostFile() throws IOException {
List<Host> hostList = new ArrayList<>();
Properties prop = new Properties();
prop.load(HostFileService.class.getClassLoader().getResourceAsStream("host.properties"));
String hostFilePath = prop.getProperty("host_file_path");
//1 读取整个文档,将文本内容保存为字符串数组,并备份到hosts中
BufferedReader bufferedReader = new BufferedReader(new FileReader(hostFilePath));
BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter("hosts.bak"));
String line = bufferedReader.readLine();
final String IP_ADDRESS_REG = "[0-9]+.[0-9]+.[0-9]+.[0-9]+";
Pattern pattern = Pattern.compile(IP_ADDRESS_REG);
while (line != null) {
HostFileService.hostFile.add(line);
//2 将其中的纯IP+Domain组合保存为Host对象,记录所在行号
Matcher m = pattern.matcher(line);
if (m.find()) {
Boolean enable = !line.trim().startsWith("#");
String ipAddress = m.group();
String domainName = line.substring(line.lastIndexOf(ipAddress));
Set<String> labels = getLabels(line);
hostList.add(Host.builder()
.line(HostFileService.hostFile.size() - 1)
.enable(enable)
.ipAddress(ipAddress)
.domainName(domainName)
.labels(labels).build());
}
bufferedWriter.write(line);
line = bufferedReader.readLine();
bufferedWriter.newLine();
}
bufferedReader.close();
bufferedWriter.close();
return hostList;
}
示例8: getAtmPhysicalPortOperationalStatus
import java.util.regex.Matcher; //导入方法依赖的package包/类
public String getAtmPhysicalPortOperationalStatus(ConsoleAccess telnet,
String atmPhysicalPortIfName) throws IOException, AbortedException {
StringTokenizer st = this.getResults(telnet, "show atm interface atm "
+ atmPhysicalPortIfName);
Matcher matcher;
while (st.hasMoreTokens()) {
matcher = atmLinkStatusPattern.matcher(st.nextToken());
if (matcher.matches()) {
return matcher.group(1);
}
}
throw new IOException("parse failed");
}
示例9: fromString
import java.util.regex.Matcher; //导入方法依赖的package包/类
/**
* Parses given string to create identifier. Numeric part may be
* in a decimal or roman numeral.
* @param idString String to parse
* @param kind Kind of identified element
* @return Created Identifier
* @throws NumberFormatException if given idString cannot be parsed
*/
public static Identifier fromString(String idString, ElementKind kind) {
if(idString.isEmpty()) {
return new Identifier(0, "", kind);
}
Pattern splitter = Pattern.compile("^(\\d+|[IVXCDL]+|)(.*)$");
Matcher m = splitter.matcher(idString);
if (!m.matches()) {
throw new NumberFormatException(String.format("idString '%s' " +
"cannot be parsed", idString));
}
String digits = m.group(1);
String chars = m.group(2).toLowerCase();
int numeric = 0;
if(RomanConverter.isRomanNumeral(digits)) {
numeric = RomanConverter.romanToInteger(digits);
} else if (!digits.isEmpty()) {
numeric = Integer.parseInt(digits);
}
return new Identifier(numeric, chars, kind);
}
示例10: loadEmitP
import java.util.regex.Matcher; //导入方法依赖的package包/类
protected void loadEmitP(String emitPFileName) throws IOException {
emitP = new HashMap();
for (Character s : STATES) {
emitP.put(s, new HashMap(10000));
}
Pattern wordPattern = Pattern.compile("'\\\\u(.*?)': (.*?),");
BufferedReader reader = new BufferedReader(new InputStreamReader(Tokenizer.class.getResourceAsStream(emitPFileName)));
String line;
Character currentType = null;
while ((line = reader.readLine()) != null) {
line = line.trim();
if (line.isEmpty())
continue;
if (line.length() == 1 && STATES.contains(line.charAt(0))) {
currentType = line.charAt(0);
continue;
} else {
if (currentType == null) {
throw new IllegalStateException("emit probability data must be followed the BEMS character");
}
}
Map<Character, Double> stateP = emitP.get(currentType);
Matcher matcher = wordPattern.matcher(line);
if (matcher.find()) {
String word = matcher.group(1);
Double p = Double.valueOf(matcher.group(2));
stateP.put((char) Integer.parseInt(word, 16), p);
}
}
}
示例11: getGrammarClass
import java.util.regex.Matcher; //导入方法依赖的package包/类
/**
* Returns the simple name of the top level class defined in the given grammar content.
*/
public static String getGrammarClass(String grammarContent) {
Matcher m = Pattern.compile("public\\ class\\ ([a-zA-Z0-9_]+)\\ ").matcher(grammarContent);
if (m.find()) {
return m.group(1);
}
return "unknown grammar class";
}
示例12: getOuter
import java.util.regex.Matcher; //导入方法依赖的package包/类
OuterSnippetsClassWrap getOuter(String className) {
Matcher matcher = PREFIX_PATTERN.matcher(className);
String cn;
if (matcher.find() && (cn = matcher.group("class")) != null) {
return classOuters.get(cn);
}
return null;
}
示例13: getUsePathForTemplate
import java.util.regex.Matcher; //导入方法依赖的package包/类
public static String getUsePathForTemplate(String patternCode, String templateName) {
String path = StringUtils.EMPTY;
Pattern pattern = Pattern.compile(String.format(PatternLabConstants.DATA_SLY_USE_TEMPLATE_PATTERN, templateName));
final Matcher matcher = pattern.matcher(patternCode);
while (matcher.find()) {
path = matcher.group(1);
}
return path;
}
示例14: committedDiff
import java.util.regex.Matcher; //导入方法依赖的package包/类
public static long committedDiff() throws Exception {
String res = (String) executeDcmd("vmNativeMemory", "detail.diff");
String[] lines = res.split("\n");
for (String line : lines) {
Matcher matcher = totalLine.matcher(line);
if (matcher.matches()) {
String committed = matcher.group(1);
return Long.parseLong(committed);
}
}
throw new Exception("Could not find the Total line in the NMT output.");
}
示例15: getDetailFromContentHeader
import java.util.regex.Matcher; //导入方法依赖的package包/类
private String getDetailFromContentHeader(String contentTypeHeader, Pattern pattern, String defaultValue, int group) {
Matcher matcher = pattern.matcher(contentTypeHeader);
return matcher.find() ? matcher.group(group) : defaultValue;
}