Example usage for java.util.regex Matcher group

List of usage examples for java.util.regex Matcher group

Introduction

In this page you can find the example usage for java.util.regex Matcher group.

Prototype

public String group(String name) 

Source Link

Document

Returns the input subsequence captured by the given named-capturing group during the previous match operation.

Usage

From source file:Main.java

public static String fixCharCode(String wholeFile) {
    long millis = System.currentTimeMillis();
    Matcher mat = CHAR_CODE_PATTERN.matcher(wholeFile);
    StringBuffer sb = new StringBuffer();
    while (mat.find()) {
        // System.gc();
        mat.appendReplacement(sb, ((char) Integer.parseInt(mat.group(1)) + ""));
    }//from   ww w .  ja  v a 2 s. c  om
    mat.appendTail(sb);
    Log.d("fix char code time: ", "" + (System.currentTimeMillis() - millis));
    return sb.toString();
}

From source file:com.opera.core.systems.OperaArguments.java

public static OperaArguments parse(String string) {
    OperaArguments parsed = new OperaArguments();

    if (string == null || string.isEmpty()) {
        return parsed;
    }//from w  w w .j av a 2  s . c om

    Pattern p = Pattern.compile("(?:-{1,2}|\\/)([\\w-]+)(?:=|\\s*)(?:\"?([^-][\\w:=\\-+_\\.\\/\\\\]*)\"?)?");
    Matcher m = p.matcher(string);

    while (m.find()) {
        parsed.add(m.group(1), m.group(2));
    }

    return parsed;
}

From source file:iox.refused.jhp.JHP_Parser.java

public static Object compile(String src) {
    StringBuffer buffer = new StringBuffer();
    buffer.append("import iox.refused.IRenderer;\n");
    buffer.append("import iox.refused.IMetaRenderer;\n");
    buffer.append("import iox.refused.IParameter;\n");
    buffer.append("import java.io.PrintWriter;\n");
    buffer.append("\n");
    src = compileImports(buffer, src);//from  www. j av  a2s  . com
    String init = null;
    List<String[]> lst = new ArrayList<String[]>();

    Matcher m = BLOCK.matcher(src);
    while (m.find()) {
        if ("init".equals(m.group(1))) {
            init = m.group(3);
        } else {
            lst.add(new String[] { m.group(2), m.group(3) });
        }
    }
    if (lst.isEmpty()) {
        if (init != null)
            src = init;
        buffer.append("void process(IParameter req,PrintWriter resp){\n");
        buffer.append("void echo(Object obj){resp.print(obj);}\n");
        compile(buffer, src);
        buffer.append("\n}\nreturn (IRenderer)this;");
    } else {
        buffer.append("IRenderer process(IParameter req){\n");
        buffer.append("void echo(Object obj){}\n");
        if (init != null)
            compile(buffer, init);
        buffer.append("return new IRenderer(){\n");
        buffer.append("void process(IParameter req,PrintWriter resp){\n");
        buffer.append("void echo(Object obj){resp.print(obj);}\n");
        int n = 0;
        for (String[] obj : lst) {
            if (n > 0)
                buffer.append("else ");
            buffer.append("if(\"" + StringEscapeUtils.escapeJava(obj[0]) + "\".equals(req.part())){\n");
            compile(buffer, obj[1]);
            buffer.append("}\n");
            n++;
        }
        buffer.append("\n}\n};");
        buffer.append("\n}\nreturn (IMetaRenderer)this;");
    }
    Interpreter i = new Interpreter();
    try {
        return i.eval(buffer.toString());
    } catch (EvalError e) {
        e.printStackTrace();
    }
    return null;
}

From source file:iox.refused.jhp.JHP_Parser.java

private static String compileImports(StringBuffer buffer, String src) {
    Matcher m = IMPORTS.matcher(src);
    StringBuffer sb = new StringBuffer();
    while (m.find()) {
        String imp = m.group(1);
        buffer.append("import ").append(imp).append(";\n");
        m.appendReplacement(sb, "");
    }//from  w w w .  j a  v a2  s .com
    m.appendTail(sb);
    return sb.toString();
}

From source file:me.StevenLawson.BukkitTelnetClient.BTC_PlayerListDecoder.java

public static final boolean checkForPlayerListMessage(final String message, final List<PlayerInfo> playerList) {
    final Matcher matcher = PLAYER_LIST_MESSAGE.matcher(message);
    if (matcher.find()) {
        final String data = matcher.group(1);
        try {//from w ww .  ja  v a 2 s.c om
            playerList.clear();

            final JSONObject json = new JSONObject(data);
            final JSONArrayIterable players = new JSONArrayIterable(json.getJSONArray("players"));
            for (JSONObject player : players) {
                final String name = getStringSafe(player, "name");
                playerList.add(new PlayerInfo(name, getStringSafe(player, "ip"),
                        getStringSafe(player, "displayName"), getStringSafe(player, "uuid"),
                        Boolean.valueOf(getStringSafe(player, "tfm.admin.isAdmin")),
                        Boolean.valueOf(getStringSafe(player, "tfm.admin.isTelnetAdmin")),
                        Boolean.valueOf(getStringSafe(player, "tfm.admin.isSeniorAdmin")),
                        getStringSafe(player, "tfm.playerdata.getTag"),
                        getStringSafe(player, "tfm.essentialsBridge.getNickname")));
            }

            Collections.sort(playerList, PlayerInfo.getComparator());

            return true;
        } catch (JSONException ex) {
        }
    }

    return false;
}

From source file:com.beyondjservlet.gateway.servlet.support.ProxySupport.java

private static void appendReplacement(final Matcher m, final StringBuffer sb, final String name,
        final String value) {
    m.appendReplacement(sb, ';' + name + '=' + (value == null ? m.group(2) : value));
}

From source file:com.yahoo.sql4dclient.BeanGenUtil.java

private static Map<String, String> getFields(String rawFields) {
    Map<String, String> fields = new HashMap<>();
    String[] args = rawFields.split(",");
    for (String arg : args) {
        Matcher fMatcher = fieldPattern.matcher(arg);
        if (fMatcher.matches()) {
            String actual = fMatcher.group(1).trim();
            String alias = fMatcher.group(3).trim();
            if (actual.matches("(COUNT|count)\\(\\*\\)(.*)")) {
                fields.put(alias, "long");
            } else if (actual.matches("(LONG_SUM|long_sum)\\((.*)\\)(.*)")) {
                fields.put(alias, "long");
            } else if (actual.matches("(DOUBLE_SUM|double_sum)\\((.*)\\)(.*)")) {
                fields.put(alias, "double");
            } else {
                fields.put(alias, "String");
            }/*from  w w w.  j a  va2 s  . c  o m*/
        } else {// Type cannot be inferred.
            fields.put(arg.trim(), "String");
        }
    }
    return fields;
}

From source file:com.music.tools.SongDBDownloader.java

private static List<String> getSongUrls(String list, HttpClient client, HttpContext ctx) throws IOException {
    String html = getResponseAsString(list, client, ctx);
    // Right, NEVER use regex for html parsing. Only this time :)
    Pattern pattern = Pattern.compile("href=\"([\\w/\\-:\\.]+)\" ");
    Matcher m = pattern.matcher(html);
    List<String> result = new ArrayList<>();
    while (m.find()) {
        result.add(m.group(1));
    }//from   ww  w.j av a 2s . c  om

    return result;
}

From source file:mitm.common.util.RegExprUtils.java

/**
 * Splits the input into the reg expression and value. The input should be provided as
 * /*from  ww w  . j av a 2s.c  o  m*/
 *  /REG-EXP/ VALUE
 * 
 * Returns null if input is null or if input does not match the above pattern
 * 
 * Example:
 * input: /^test$/ abc def -> [0]=^test$ [1]=abc def 
 */
public static String[] splitRegExp(String input) {
    if (StringUtils.isEmpty(input)) {
        return null;
    }

    Matcher matcher = SPLIT_REG_EXP_PATTERN.matcher(input);

    String[] result = null;

    if (matcher.matches()) {
        result = new String[] { matcher.group(1), matcher.group(2) };
    }

    return result;
}

From source file:cc.recommenders.mining.calls.QueryOptions.java

private static double parseMin(String in) {
    Pattern p = compile(".*\\+MIN([0-9]+).*");
    Matcher m = p.matcher(in);
    if (m.matches()) {
        return parseDouble(m.group(1)) / 100.0;
    } else {/*  w  ww. ja va  2s  .c  o  m*/
        return 0.0;
    }
}