当前位置: 首页>>代码示例>>Java>>正文


Java Matcher.groupCount方法代码示例

本文整理汇总了Java中java.util.regex.Matcher.groupCount方法的典型用法代码示例。如果您正苦于以下问题:Java Matcher.groupCount方法的具体用法?Java Matcher.groupCount怎么用?Java Matcher.groupCount使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.regex.Matcher的用法示例。


在下文中一共展示了Matcher.groupCount方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: genWinArgs

import java.util.regex.Matcher; //导入方法依赖的package包/类
/**
 * Does a poor-man's parse of a MSDOS command line and parses it
 * into a WIndows cmd.exe invocation to approximate.
 */
static private String[] genWinArgs(String monolithic) {
    List list = new ArrayList();
    list.add("cmd.exe");
    list.add("/y");
    list.add("/c");
    Matcher m = wincmdPattern.matcher(monolithic);
    String[] internalTokens;
    while (m.find()) {
        for (int i = 1; i <= m.groupCount(); i++) {
            if (m.group(i) == null) continue;
            if (m.group(i).length() > 1 && m.group(i).charAt(0) == '"') {
                list.add(m.group(i).substring(1, m.group(i).length() - 1));
                continue;
            }
            internalTokens = m.group(i).split("\\s+");
            for (int j = 0; j < internalTokens.length; j++)
                list.add(internalTokens[j]);
        }
    }
    return (String[]) list.toArray(new String[] {});
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:26,代码来源:SqlFile.java

示例2: ofMatcher

import java.util.regex.Matcher; //导入方法依赖的package包/类
public static XmEntityKey ofMatcher(String xmKey, Pattern pattern) {
    Objects.requireNonNull(xmKey, "XM entity key can't be null");

    Matcher xmKeyMatcher = pattern.matcher(xmKey);
    if (!xmKeyMatcher.matches()) {
        // add more appropriate exception ...
        throw new BusinessException("XM entity key '" + xmKey + "' doesn't match pattern: "
                                               + pattern.pattern());
    }

    int count = xmKeyMatcher.groupCount();
    String groups[] = new String[count];
    for (int i = 0; i < count; i++) {
        groups[i] = xmKeyMatcher.group(i + 1);
    }
    return new XmEntityKey(xmKey, groups);
}
 
开发者ID:xm-online,项目名称:xm-ms-entity,代码行数:18,代码来源:XmEntityKey.java

示例3: handleUserstate

import java.util.regex.Matcher; //导入方法依赖的package包/类
/**
 * Parses the received line and saves data such as the users color, if the user is mod, subscriber or turbouser
 * @param line
 */
private void handleUserstate(String line) {
	Matcher userstateMatcher = userStatePattern.matcher(line);
	if(userstateMatcher.find()) {
		userColor = userstateMatcher.group(1);
		userDisplayName = userstateMatcher.group(2);
		String emoteSets = userstateMatcher.group(3);
		userIsMod = userstateMatcher.group(4).equals("1");
		userIsSubscriber = userstateMatcher.group(5).equals("1");
		if (userstateMatcher.groupCount() > 7) {
			userIsTurbo = userstateMatcher.group(7).equals("1");
		}

	} else {
		Log.e(LOG_TAG, "Failed to find userstate pattern in: \n" + line);
	}
}
 
开发者ID:SebastianRask,项目名称:Pocket-Plays-for-Twitch,代码行数:21,代码来源:ChatManager.java

示例4: extract

import java.util.regex.Matcher; //导入方法依赖的package包/类
private static String extract(String response, Pattern p) {
    Matcher matcher = p.matcher(response);
    if (matcher.find() && matcher.groupCount() >= 1) {
        return OAuthEncoder.decode(matcher.group(1));
    } else {
        throw new OAuthException("Response body is incorrect. Can't extract token and secret from this: " + response);
    }
}
 
开发者ID:fivef,项目名称:add_to_evernote_note,代码行数:9,代码来源:EvernoteOAuthHelper.java

示例5: getCorrectGroup

import java.util.regex.Matcher; //导入方法依赖的package包/类
private static String getCorrectGroup(Matcher matcher) {
    for (int i = matcher.groupCount(); i > 0; i--) {
        final String group = matcher.group(i);
        if (group != null) {
            return group;
        }
    }
    throw new IllegalStateException("Group cannot be empty");
}
 
开发者ID:jhkst,项目名称:dlface,代码行数:10,代码来源:MethodBuilder.java

示例6: fromString

import java.util.regex.Matcher; //导入方法依赖的package包/类
public static MethodSignature fromString(String signatureString) {
    if (signatureString == null) {
        return null;
    }
    Matcher matcher = SIGNATURE_STRING_PATTERN.matcher(signatureString);
    if (matcher.find()) {
        if (matcher.groupCount() != 3) {
            throw new IllegalArgumentException("invalid signature");
        }
        return new MethodSignature(matcher.group(1), matcher.group(2), matcher.group(3).split(","));
    } else {
        throw new IllegalArgumentException("invalid signature");
    }
}
 
开发者ID:cadox8,项目名称:PA,代码行数:15,代码来源:MethodWrapper.java

示例7: runNonTransparentProxyTest

import java.util.regex.Matcher; //导入方法依赖的package包/类
/**
* runs the non transparent proxy test:
* 
* 1. open socket on requested port and send "OK" to let client continue the test 
* 2. wait for incoming HTTP protocol request
* 3. send request back to client (echo)
*  
   * @param command
   * @throws IOException 
   * @throws InterruptedException 
   */
  private void runNonTransparentProxyTest(String command) throws Exception {
int echoPort;

Pattern p = Pattern.compile(QoSServiceProtocol.CMD_NON_TRANSPARENT_PROXY_TEXT + " ([\\d]*)");
Matcher m = p.matcher(command);
m.find();
if (m.groupCount()!=1) {
	throw new IOException("non transparent proxy test command syntax error: " + command);
}
else {
	echoPort = Integer.parseInt(m.group(1));
}

try {
	TestServer.registerTcpCandidate(echoPort, socket);
	
	sendCommand(QoSServiceProtocol.RESPONSE_OK, command);
	TestServerConsole.log("NTP: sendind OK. waiting for request...", 1, TestServerServiceEnum.TCP_SERVICE);
}
catch (Exception e) {
	TestServerConsole.error(name, e, 1, TestServerServiceEnum.TCP_SERVICE);
}
finally {
	//is beeing done inside TcpServer now:
	//tcpServer.removeCandidate(socket.getInetAddress());
}
  }
 
开发者ID:rtr-nettest,项目名称:open-rmbt,代码行数:39,代码来源:ClientHandler.java

示例8: fromString

import java.util.regex.Matcher; //导入方法依赖的package包/类
/**
 * Given a token string like 'T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX', creates a {@link WebHookToken} object.
 *
 * @param string {@link String} formatted like 'T????????/B????????/????????????????????????'
 * @return the {@link WebHookToken}
 * @throws IllegalArgumentException if the {@code string} is not a valid token
 */
public static WebHookToken fromString(String string) {
    Matcher matcher = TOKEN_PATTERN.matcher(string);
    if (matcher.find() && matcher.groupCount() == 3) {
        return WebHookToken.builder()
                .partT(matcher.group(1))
                .partB(matcher.group(2))
                .partX(matcher.group(3))
                .build();
    }
    throw new IllegalArgumentException(
            String.format("Unable to parse text as %s: %s", WebHookToken.class.getName(), string));
}
 
开发者ID:palantir,项目名称:roboslack,代码行数:20,代码来源:WebHookToken.java

示例9: c_groups

import java.util.regex.Matcher; //导入方法依赖的package包/类
String c_groups(String input) {
	Matcher m = this.pattern.matcher(input);
	
	boolean r = m.find();
	if(!r) return null;
	
	StringBuilder builder = new StringBuilder();
	for(int i = 1; i <= m.groupCount(); i++) builder.append(m.group(i));
	return builder.toString();
}
 
开发者ID:gkatev,项目名称:yify-subtitles,代码行数:11,代码来源:YifySub.java

示例10: findVersion

import java.util.regex.Matcher; //导入方法依赖的package包/类
private String findVersion(Pattern pattern) {
	WebView wv = new WebView(this.getApplicationContext());
	final String userAgent = wv.getSettings().getUserAgentString();
	if (userAgent != null) {
		final Matcher matcher = pattern.matcher(userAgent);
		if (matcher != null && matcher.find() && matcher.groupCount() == 2) {
			return matcher.group(2);
		}
	}
	return null;
}
 
开发者ID:fengshihao,项目名称:WebPager,代码行数:12,代码来源:MainActivity.java

示例11: runRcvCommand

import java.util.regex.Matcher; //导入方法依赖的package包/类
/**
   * 
   * @param command
   * @param token
   * @throws IOException
   */
  private void runRcvCommand(String command, ClientToken token, boolean isIncoming) throws IOException {
Pattern p = Pattern.compile((isIncoming ? QoSServiceProtocol.REQUEST_UDP_RESULT_IN : QoSServiceProtocol.REQUEST_UDP_RESULT_OUT) + " ([\\d]*)");
Matcher m = p.matcher(command);
m.find();

if (m.groupCount()!=1) {
	throw new IOException("RCV command syntax error: " + command);
}
else {
	final int port = Integer.parseInt(m.group(1));
	sendRcvResult(isIncoming ? clientUdpInDataMap.get(port) : clientUdpOutDataMap.get(port), port, command);
}
  }
 
开发者ID:rtr-nettest,项目名称:open-rmbt,代码行数:20,代码来源:ClientHandler.java

示例12: saturate

import java.util.regex.Matcher; //导入方法依赖的package包/类
@Override
public Collection<Name> saturate(Name name) {
	Matcher m = pattern.matcher(name.name);
	if (!m.matches())
		return Collections.emptyList();
	String[] groups = new String[m.groupCount() + 1];
	for (int i = 0; i < groups.length; ++i)
		groups[i] = m.group(i);
	Collection<Name> result = new ArrayList<Name>(formats.size());
	for (MessageFormat fmt : formats) {
		String s = fmt.format(groups);
		result.add(new Name(s, type));
	}
	return result;
}
 
开发者ID:Bibliome,项目名称:bibliome-java-utils,代码行数:16,代码来源:SaturatePattern.java

示例13: getChineseCount

import java.util.regex.Matcher; //导入方法依赖的package包/类
public static int getChineseCount(String str) {
    int count = 0;
    Pattern p = Pattern.compile(regEx);
    Matcher m = p.matcher(str);
    while (m.find()) {
        for (int i = 0, groupCount = m.groupCount(); i <= groupCount; i++) {
            count = count + 1;
        }
    }
    return count;
}
 
开发者ID:Jusenr,项目名称:androidtools,代码行数:12,代码来源:StringUtils.java

示例14: ApiResponse

import java.util.regex.Matcher; //导入方法依赖的package包/类
public ApiResponse(Response<T> response) {
  code = response.code();
  if (response.isSuccessful()) {
    body = response.body();
    errorMessage = null;
  } else {
    String message = null;
    if (response.errorBody() != null) {
      try {
        message = response.errorBody().string();
      } catch (IOException ignored) {

      }
    }
    if (message == null || message.trim().length() == 0) {
      message = response.message();
    }
    errorMessage = message;
    body = null;
  }
  String linkHeader = response.headers().get("link");
  if (linkHeader == null) {
    links = Collections.emptyMap();
  } else {
    links = new ArrayMap<>();
    Matcher matcher = LINK_PATTERN.matcher(linkHeader);

    while (matcher.find()) {
      int count = matcher.groupCount();
      if (count == 2) {
        links.put(matcher.group(2), matcher.group(1));
      }
    }
  }
}
 
开发者ID:charlesng,项目名称:SampleAppArch,代码行数:36,代码来源:ApiResponse.java

示例15: getVersion

import java.util.regex.Matcher; //导入方法依赖的package包/类
public static Version getVersion() {
    String name = Bukkit.getServer().getClass().getPackage().getName();
    String versionPackage = name.substring(name.lastIndexOf('.') + 1) + ".";
    for (Version version : values()) {
        if (version.matchesPackageName(versionPackage)) {
            return version;
        }
    }
    System.err.println("[ReflectionHelper] Failed to find version enum for '" + name + "'/'" + versionPackage + "'");

    System.out.println("[ReflectionHelper] Generating dynamic constant...");
    Matcher matcher = NUMERIC_VERSION_PATTERN.matcher(versionPackage);
    while (matcher.find()) {
        if (matcher.groupCount() < 3) {
            continue;
        }

        String majorString = matcher.group(1);
        String minorString = matcher.group(2);
        if (minorString.length() == 1) {
            minorString = "0" + minorString;
        }
        String patchString = matcher.group(3);
        if (patchString.length() == 1) {
            patchString = "0" + patchString;
        }

        String numVersionString = majorString + minorString + patchString;
        int numVersion = Integer.parseInt(numVersionString);
        String packge = versionPackage.substring(0, versionPackage.length() - 1);

        try {
            // Add enum value
            Field valuesField = new FieldResolver(Version.class).resolve("$VALUES");
            Version[] oldValues = (Version[]) valuesField.get(null);
            Version[] newValues = new Version[oldValues.length + 1];
            System.arraycopy(oldValues, 0, newValues, 0, oldValues.length);
            Version dynamicVersion = (Version) newEnumInstance(Version.class, new Class[]{
                    String.class,
                    int.class,
                    int.class}, new Object[]{
                    packge,
                    newValues.length - 1,
                    numVersion});
            newValues[newValues.length - 1] = dynamicVersion;
            valuesField.set(null, newValues);

            System.out.println("[ReflectionHelper] Injected dynamic version " + packge + " (#" + numVersion + ").");
            System.out.println("[ReflectionHelper] Please inform inventivetalent about the outdated version, as this is not guaranteed to work.");
            return dynamicVersion;
        } catch (ReflectiveOperationException e) {
            e.printStackTrace();
        }
    }

    return UNKNOWN;
}
 
开发者ID:cadox8,项目名称:PA,代码行数:58,代码来源:Minecraft.java


注:本文中的java.util.regex.Matcher.groupCount方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。