我在 dart 中嘗試了以下代碼,但無法獲得解決方案。
RegExp rgb = RegExp(r"^rgb\(([0-9] ),\s*([0-9] ),\s*([0-9] )\)$");
final match = rgb.allMatches("rgb(127, 127, 126)");
我可以使用rgb.exec(String)回傳陣列的方法使用上述正則運算式在javascript中輕松完成。
uj5u.com熱心網友回復:
您可以使用以下groups方法獲取捕獲組:
RegExp rgb = RegExp(r"^rgb\(([0-9] ),\s*([0-9] ),\s*([0-9] )\)$");
final matches = rgb.allMatches("rgb(127, 127, 126)");
for (final match in matches) {
final colors = match.groups([1, 2, 3]);
print('red: ${colors[0]}, green: ${colors[1]}, blue: ${colors[2]}');
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/316101.html
