My string is: (some text followed by) User ‘Mr.G@rr!s0n’ is the admin.
I am using this regex pattern: /user\s'(.*)'\sis/i
However, I am getting the output as Mr.G!s0n
What exactly do I need to change in my regex pattern?
Here is the code snippet:
$text1 = "user 'Mr.G@rr!s0n' is the admin";
if($text1 =~ /user\s'(.*)'\sis/i)
{
print "\n";
print "Password: ".$1;
print "\n";
}
I am guessing your code (that you won’t show for some reason) is something like this:
The problem here is that
@rris interpolated because you are using a double quoted string. Since you are obviously not using:..this error is silent. If you had used them, you would have gotten:
To fix the problem, single quote your string using either
''orq():As you notice, I used
#as delimiter forq(), because both single quote and parentheses were already in the string.The other possibility is that you are using your match in some kind of evaluation, but that would be silly. So I am not going to make guesses there.