1

テキストの塊を含む変数があります

$foo = "
    Garbage directory
    /test/this/is/a/directory
    /this/is/another/foo\nThisd is is\nDrop stuff testing\nRandom stuff emacs is great";

正規表現を使用して行を取得するにはどうすればよいですか/test/this/is/a/directory

私はこれを試しました:

my $foo = "
    Garbage directory
    /test/this/is/a/directory
    /this/is/another/foo\nThisd is is\nDrop stuff testing\nRandom stuff emacs is great";
$foo =~ /^\/test.*$/;
print "\n$foo\n";

しかし、これはテキストの塊全体を印刷し続けるだけです。

4

3 に答える 3

1

表現を変えて

$foo =~ m~^\s*/test.*$~m;

regex101.comでデモをご覧ください。


これは、他の区切り文字 ( ) を使用して、さらに空白 ( ) をエスケープし、モードをオン( )~にする必要がないようにします。/\s*multilinem

于 2018-05-23T20:28:06.600 に答える