gpt4 book ai didi

java - 使用正则表达式替换字符串

转载 作者:行者123 更新时间:2023-12-02 07:09:27 25 4
gpt4 key购买 nike

用 Java 中的正则表达式替换 -我有一个字符串

    allof{    condition {licenseState=="NY"}    condition{professionId==301}    condition  {professionId=="301"}}

would be it's possible to do a replacement in java using regex so the string looks like this one:

    allof{    condition 'licenseState=="NY"', {licenseState=="NY"}    condition 'professionId==301', {professionId==301}    condition 'professionId=="301"', {professionId=="301"}    }  

basically getting what inside the {} brackets and putting it separately. Is it possible and how? NewLine char is not guaranteed to be present after each condition.

I've tried:

condition\s*?{[a-zA-Z0-9=<>\s"']*} 

最佳答案

您可以使用string replaceAll功能。像这样的事情:

yourString.replaceAll("\\{([^{}]*\\=\\=[^{}]*)\\}", "'$1', {$1}");

关于java - 使用正则表达式替换字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15709548/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com