Problem mit Regex

Status
Nicht offen für weitere Antworten.

Illuvatar

Top Contributor
Ich habe so einen Code (zum Testen 😉 ):
Code:
		Pattern p = Pattern.compile("(?:x(.*?)\n)*", Pattern.DOTALL);
		Matcher m = p.matcher ("xa\nxb\nxc\n");
		m.find();
		for (int i = 1; i <= m.groupCount();){
			System.out.println (m.group (i++));
		}
Die Ausgabe ist "c".
Weiß jemand, wie ich auch an "a" und "b" rankomme?

Thx im Voraus 😉
 
Also das hab ich grad in der API gefunden:
The captured input associated with a group is always the subsequence that the group most recently matched. If a group is evaluated a second time because of quantification then its previously-captured value, if any, will be retained if the second evaluation fails. Matching the string "aba" against the expression (a(b)?)+, for example, leaves group two set to "b". All captured input is discarded at the beginning of each match.
Sieht also schlecht aus 🙁 Ich fürchte das muss ich anders machen. Oder?
 
Ah jetzt:
Code:
		Pattern p = Pattern.compile("x(.*?)\n", Pattern.DOTALL);
		Matcher m = p.matcher (toInterpret);
		while (m.find()){
			System.out.println (m.group(1));
		}

So tuts.
-->closed
 
Status
Nicht offen für weitere Antworten.

Neue Themen


Zurück
Oben