\b(?<![.-])(?!000|666)[0-8][0-9]{2}-(?!00)[0-9]{2}-(?!0000)[0-9]{4}\b(?![.-])
This is the same as your regex, but it also excludes surrounding dashes and dots (feel free to add to those character classes, but ensure that the dash (-
) is always at the end or else it'll create a range).
\b
matches a word break. You probably know this, but that means one side of it (either before or after but not both) must be a word character (a letter, number, or underscore) and the other side (either after or before but not both) must not be a word character (it may instead be a line break or nonexistent due to having reached the beginning/end of the string). You want this, but you want to exclude a few more things too. Therefore:
\b(?<![.-])
means that after the word break, check the previous character (if any). It must not match [.-]
(a single character that is either dot or dash).
\b(?![.-])
means that after the word break, the next character (if any) must not match [.-]
.
When I say "if any" I am referring to the possibility that there is a line break, start of file, or end of file instead. Those will all satisfy these negative lookarounds.
See also this full regex explanation, with examples, at regex101