2017-08-05 8 views
-1

Der unten stehende Code wird immer mit "Nein" gedruckt. Irgendwelche Ideen ?Regex passt nicht richtig

import java.util.*; 
import java.lang.*; 
import java.util.regex.Matcher; 
import java.util.regex.Pattern; 

class Rextester 
{ 
    public static void main(String args[]) 
    { 
     String field= "superCategory(code)[composite={catalog: $catalog}]"; 

     Pattern FULL_PATTERN = Pattern 
      .compile("\\[composite\\s*=\\s*\\{([^)]+)\\}\\]"); 

     final Matcher matcher = FULL_PATTERN.matcher(field); 
     if (matcher.matches()) { 
      System.out.println("yes"); 
     } else { 
      System.out.println("no"); 

     } 
    } 
} 
+3

Verwenden '.find()' statt '.matches()' – anubhava

Antwort

0

sollten Sie das Muster find, nicht matches:

if (matcher.find()) {