java - 使用 split 或 tokenizer 将字符串放入大括号内的方法

标签 java string split stringtokenizer

String s = "author= {insert text here},";

试图获取字符串的内部,我环顾四周,但找不到仅使用 split 或 tokenizer 的解决方案...

到目前为止我正在这样做

arraySplitBracket = s.trim().split("\\{", 0);

这让我在此处插入文本}, 在 array[1] 但 id 就像不附加 } 的方式

也尝试过

StringTokenizer st = new StringTokenizer(s, "\\{,\\},");

但它给了我 author= 作为输出。

最佳答案

public static void main(String[] args) {
        String input="{a c df sdf TDUS^&%^7 }";     
        String regEx="(.*[{]{1})(.*)([}]{1})";
        Matcher matcher = Pattern.compile(regEx).matcher(input);            

        if(matcher.matches()) {         
            System.out.println(matcher.group(2));
        }
}

关于java - 使用 split 或 tokenizer 将字符串放入大括号内的方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53058126/

相关文章:

python - 如何用数字和字母拆分 Python 字符串?

java - Springframework.dao.InvalidDataAccessResourceUsageException hibernate .SQLGrammarException MySQLSyntaxErrorException

java - 为什么对象数组中的元素没有更新?

java - 如何在 Tomcat 服务器上运行的 Spring MVC 应用程序中使用单个 "application wide"线程池

algorithm - 在不到 O(n) 的时间内搜索与模式 "abc:*:xyz"匹配的字符串

xml - 根据字符串分割XML文件

java - 通过不同的方法更改和使用变量

c - 对结构成员的字符串操作

c++ - 对一串罗马数字进行排序

python - 访问 split 函数后的最后一个字符串以创建新列表