我想比較一個變量和正則表達式中的另一個變量。如果變量的內容完全相同,匹配會很好,但如果值的順序不同,我希望匹配發生。Perl的正則表達式匹配忽略順序
例子:
#!/usr/bin/perl
my $output = "test0 test1";
my $expected_output = "test1 test0";
my $expected_regex = qr/^$expected_output\s*$/;
print "Expected_regex :: $expected_regex\n";
if ($output =~ $expected_regex) {
print "pass\n";
}
在我的例子,我能做些什麼來讓$output = $expected_regex
即使它們包含相同的值,但不會以相同的順序?
如果您的輸入模式不像您在此處所述的那樣「簡單」,請編輯您的問題(短但具有代表性)的「真實生活」示例,以便我們更好地瞭解您正在嘗試執行的操作。 – Mat