in reply to Word boundary in regexp
is equivalent to\b
(?:(?<=\w)(?!\w)|(?<!\w)(?=\w))
If you want to include "-" as a word character, just change \w to [\w-].
(?:(?<=[\w-])(?![\w-])|(?<![\w-])(?=[\w-]))
All together, that gives
my $my_slash_b = qr/(?:(?<=[\w-])(?![\w-])|(?<![\w-])(?=[\w-]))/; /$my_slash_b$check$my_slash_b/
But since you "know" that $check starts and ends with a word character, the above simplifies to
/(?<![\w-])$check(?![\w-])/
If you wanted to go further and count any non-whitepspace as word characters, you're left with
my $my_slash_b = qr/(?:(?<=\S)(?!\S)|(?<!\S)(?=\S))/; /$my_slash_b$check$my_slash_b/
and thus
/(?<!\S)$check(?!\S)/
|
|---|