I have a simple program where the user can enter a string.
After this the user can enter a regex. I need the string to be compared against this regex.
The following code do not work – the regex always fails.
And I know that its maybe because I am comparing a string with a string and not a string with a regex.
But how would you do this?
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";
}
}
You need to use a
//,m//, ors///— but you can specify a variable as the pattern.