Java 如何在四个分隔符之间创建正则表达式匹配

Java 如何在四个分隔符之间创建正则表达式匹配,java,android,regex,Java,Android,Regex,我需要得到介于[COLOR dxvx]和[/COLOR]之间的字符串yyy。如何在Java中使用正则表达式来实现这一点 在[COLOR dxvx]中,注意到颜色词旁边的[COLOR dxvx]也在变化使用捕获组 String name="[COLOR dxvx]yyyy[/COLOR]" String name="[COLOR dvvx]tttt[/COLOR]" 您还可以尝试直接匹配: Matcher m = Pattern.compile("\\[COLOR\\s+dxvx\\](.*?)

我需要得到介于[COLOR dxvx]和[/COLOR]之间的字符串yyy。如何在Java中使用正则表达式来实现这一点

在[COLOR dxvx]中,注意到颜色词旁边的[COLOR dxvx]也在变化

使用捕获组

String name="[COLOR dxvx]yyyy[/COLOR]"
String name="[COLOR dvvx]tttt[/COLOR]"

您还可以尝试直接匹配:

Matcher m = Pattern.compile("\\[COLOR\\s+dxvx\\](.*?)\\[/COLOR\\]").matcher(s);
while(m.find()) {
  System.out.println(m.group(1));
 }

谢谢你的回复。在[COLOR dxvx]这一方,“COLOR”旁边的世界没有定义。这一点也在发生变化。请尝试
“\\[COLOR\\s+\\w+\\](.*?\\\[/COLOR\\]””
到目前为止您尝试了什么?
(?<=])[^]]+(?=\\[/COLOR)
public static void main(String[] args){
    String[] strings = {"String name=\"[COLOR dxvx]yyyy[/COLOR]\"",
            "String name=\"[COLOR dvvx]tttt[/COLOR]\""};

    for(String string : strings) {
        ArrayList<Integer> numbers = new ArrayList<Integer>();
        Matcher matcher = Pattern.compile("(?<=])[^]]+(?=\\[/COLOR)").matcher(string);
        if(matcher.find()){
            System.out.println(matcher.group());
        }

    }
}
yyyy
tttt