$text_to_search = "example text with [foo] and more"; $search_string = "[foo]"; if($text_to_search =~ m/$search_string/) print "wee";
Please follow the code above. For some reason, I would like to find the text "[foo]" in the variable $ text_to_search and print "wee" if I find it. For this, I would have to make sure that [and] is replaced by [and] so that Perl treats it as characters instead of operators.
Question: How can I do this without first having to replace [ and ] with \[ and \] using the expression s/// ?
regex perl
Stefan Jan 06 2018-11-11T00: 00Z
source share