有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!


共 (2) 个答案

  1. # 1 楼答案

    这将是解析函数的起点:

    /** example: findCharIndex(subject, ':'); */
    public static int findCharIndex(String subject, char findChar)
    {
        boolean insideQuotes = false;
        boolean insideTags = false;
        for (int index = 0; index < subject.length(); index++)
        {
            char ch = subject.charAt(index);
            if (ch == '"')
                insideQuotes = !insideQuotes;
            else if (!insideQuotes)
            {
                if (ch == '<')
                    insideTags = true;
                else if (insideTags && ch == '>')
                    insideTags = false;
            }
            if (!insideQuotes && !insideTags && ch == findChar)
                return index;
        }
        return -1;
    }
    
  2. # 2 楼答案

    执行匹配比拆分更容易

    (?:[^"<:]|"[^"]*"|<[^>]*)*