我有一个简单的程序,用户可以在其中输入字符串。在此之后,用户可以输入正则表达式。我需要将字符串与此正则表达式进行比较。
以下代码不起作用 - 正则表达式总是失败。
而且我知道这可能是因为我将字符串与字符串进行比较,而不是字符串与正则表达式进行比较。
但是你会怎么做呢?
while(1){
print "Enter a string: ";
$input = <>;
print "\nEnter a regex and see if it matches the string: ";
$regex = <>;
if($input =~ $regex){
print "\nThe regex $regex matched the string $input\n\n";
}
}