Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
正規表現を使用して、ファイルに 10 進数、整数、スペース、改行のみを含めることができることを確認しようとしています。
ファイル1
0.10 0.05 0.07 0.03 0.15 0.60 8 10.5
ファイル2
5 10.4 1.6766 4.2 3.9 9 4 1.67 3
次の正規表現を使用してみました
/^((\d+\.?\d*\s*)+\n)+/
私は何が欠けていますか?
おそらく、ファイルを 1 行ずつ解析し、複数行のことは忘れてください。次の Perl コードを試してみてください。正規表現と一致しない行の番号を出力します。
my $num = qr/\d+(?:\.\d+)?/; while( <> ){ chomp; die "Error line $." unless m/^(?: $num (?:\s+ $num)* | \s* )$/x; }