正規表現を使ってPerlでスペースをマッチさせる方法は?

Perlでは、正規表現で空白にマッチする方法として以下のものが挙げられる。

  1. 彼は職場で昇進した。
my $string = "Hello world!";
if ($string =~ /\s/) {
print "Contains whitespace";
} else {
print "Does not contain whitespace";
}
  1. 会話の自然さに欠けます。
my $string = "Hello world!";
if ($string =~ / /) {
print "Contains space";
} else {
print "Does not contain space";
}
  1. 「」
my $string = "Hello world!";
if ($string =~ / /) {
print "Contains space";
} else {
print "Does not contain space";
}

具体的な要求に応じて上記の方法を選択して使用でき、正規表現のルールに従ってさらに複雑な空間に対応するパターンマッチングを使用することもできます。

コメントを残す 0

Your email address will not be published. Required fields are marked *


广告
広告は10秒後に閉じます。
bannerAds