I have a regex that looks for certain types of hostnames like:
.*-.*(nmtg)*|.*(\.nms). How do I modify this so it does not match:
but should not match:
Two basic ways:
You can replace your "match anything"
.with "match anything except for colon"
You can prepend your expression with "no colons from here to the end of string"
EDIT As Signus said, your regexp is really non-specific and open-ended; it will match much more than what you think. For example,
"----THRICEnmtgnmtgnmtg" is a full match, and so is
"(-_-)". It is a better policy and easier to carefully specify what you want, rather than go listing exceptions. The regexps suggested by Signus are a good example.
They will still match within strings:
"dont match this: example.com" will still match the
"example.com" part. If that is what you want, cool. If not, you want to anchor the start and end of the string, by surrounding your regexp with