1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| public static void main(String[] args) {
final String s = "Objet[id=100,name=car,type=grey,source=sourceId{id=12,version=12},linked=true]";
final Matcher matcherLevel1 = Pattern.compile("\\w+" // une suite d'au moins une lettre
+ "?=" // jusqu'au = suivant
+ "(" // suivi ...
+ "\\p{Alnum}" // ... d'une lettre ou un chiffre
+ "|" // ... ou d'un ...
+ "("
+ "\\{.*?\\}" // ... nombre quelconque de caractères entre accolades (sauf accolade fermante)
+ ")"
+ ")" // fin de capture
+ "+" // au moins une fois
).matcher(s);
while( matcherLevel1.find() ) {
String[] split = matcherLevel1.group().split("=", 2);
System.out.println("Property: " + split[0] + " Value: " + split[1]);
}
} |