這裏是我試圖捕捉使用Ruby我的測試字符串:如何使用REGEX匹配捕獲多個模式? (紅寶石)
<?lang
this_should_be_captured();
and_also_this();
and_this();
?>
this text should NOT be captured
<?lang this_should_also_be_captured(); ?>
當我使用正則表達式:
(<\?lang(\n|.)*\?>)
匹配捕捉一切(包括一部分我不想要:「不應該捕獲該文本」),如http://rubular.com/r/qSOOzq6HAx所示。
我怎樣才能正確地捕捉到兩個不同的塊,而不捕捉我不想要什麼?
完美!你太棒了。非常感謝Alex :) – sjsc 2011-04-10 11:55:15
@sjsc謝謝! – alex 2011-04-10 11:55:38