私のデータ:
stack: 123 overflow: 456 others: - st: 7 ov: 7 againothers: - m: 11 t: 12 - m: 13 t: 14 - m: 15 t: 16 - st: 8 ov: 8 againothers: - m: 17 t: 18 end: 42
私の正規表現:
^stack: (\d+) overflow: (\d+) others: ?(.+) end: (\d+)$
グループは次のように一致します。
1: 123
2: 456
3: - st: 7 ov: 7 againothers: - m: 11 t: 12 - m: 13 t: 14 - m: 15 t: 16 - st: 8 ov: 8 againothers: - m: 17 t: 18
4: 42
これまでのところ良い。グループ 3 で、次の正規表現を実行します。
^(?:- st: (\d+) ov: (\d+) againothers: ?(?: - m: (\d+) t: (\d+))+)+$
それはまったく機能しません(なぜですか?)ので、 and を削除する^
と$
一致します。一致は次のようになります。
1: 7 // <-- Works as expected.
2: 7
3: 15 // <-- Here I'd expected 2 groups matching: (13,14), (15,16)
4: 16 // <-- but I'm only getting the last group.
1: 8 // <-- This works and the remainder is as expected.
2: 8
3: 17
4: 18
1 つ以上の(?: - m: (\d+) t: (\d+))+
組み合わせに一致する "13, 14" 内部グループが欠落しているようです。
オンラインテスト: http://gskinner.com/RegExr/?33urf- st: 7 ov: 7 againothers: - m: 11 t: 12 - m: 13 t: 14 - m: 15 t: 16 - st: 8 ov: 8 againothers: - m: 17 t: 18
。(?:- st: (\d+) ov: (\d+) againothers: ?(?: - m: (\d+) t: (\d+))+)+
http://www.regular-expressions.info/captureall.htmlを読みましたが、私の問題はそれに関連していると思いますか? 1 つ以上の m:t: の組み合わせを一致させるためのヒント/ポインター/ヘルプはありますか?