英文:
Replace regular expression groups JAVA
问题
String finalLine = line.replaceAll("(\\[\\[)(,)(],)(]])", "$1 ,$2,$3\n,$4");
英文:
I'm trying to do a group replacement, I don't know if it's possible to do with just one expression
Text
String line = "[[A, _, _, _, A], [_, A, _, A, _]]";
Expected text
String line = "A _ _ _ A\n_ A _ A _";
Regex: ([[)(,)(],)(]])
Test #1 String finalLine = line.replaceAll("(\\[\\[)(,)(],)(]])", "$1 ,$2,$3\n,$4");
Test #2 String finalLine = line.replaceAll("(\\[\\[)(,)(],)(]])", " ,,\n,"):
Test #3 String finalLine = line..replace ( "]", "]\n" ).replace ( "[[", " " ).replaceAll ( "(])|(,)|(\\[)", "" );
答案1
得分: 1
以下是翻译好的代码部分:
line = line.replaceAll("],", "\n").replaceAll(",", " ").replaceAll("[\\[\\]]", "");
英文:
Try this:
line = line.replaceAll("],", "\n").replaceAll(",", " ").replaceAll("[\\[\\]]", "");
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论