I want to find sequences matching my regular expression if they are in the middle of a line surrounded by spaces, at the end or at the beginning, or will be the only thing in the line.
Example: Suppose the sequence 'qwe45rty' is what we are looking for. I want to be able to get a positive result on all of these lines:
'qwe45rty' 'qwe45rty blabla' 'smth qwe45rty blabla' 'smth qwe45rty' ' qwe45rty '
But not one of them:
'aaqwe45rty' 'qwe45rtybb' 'aaqwe45rtybb'
The best I came up with is something like this:
if ( ($a =~ /\s+$re\s+/) or ($a =~ /^$re\s+/) or ($a =~ /\s+$re$/) or ($a =~ /^$re$/) ) {
which may not be the best way to do this :)
Any suggestions?
source share