Question: I have a regex that looks for certain types of hostnames like: `.*-.*(nmtg)*|.*(\.nms)`. How do I modify this so it does not match: `11.22:33:44:55-66`?

Should match:

```
cs25-admin.nmtg.company.com 
cs25-admin

```

but should not match:

```
11.22:33:44:55-66

```

Answer: 
Two basic ways:

* You can replace your "match anything" `.` with "match anything except for colon" `[^:]` everywhere
* 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 `/^.....$/`.
You're using the `*` quantifier that matches 0 or more of the preceding token, in which case you supplied `.` which is a token that matches any character except line breaks.

To match domain names with subdomain names you can do the following:

```
(\w+\.)?\w+\.(com|org)

```

And to really match any domain with a TLD I like to do this:

```
([a-zA-Z0-9]+\.){1,2}[a-zA-Z]{2,4}

```

Where the latter will match any domain with a single subdomain using the numeric quantifer `{num}` which allows you to specify a range of matches, as shown in the above regex. 

This allows you to match a group of alphanumeric characters followed by a period 1 to 2 times (i.e. subdomain.domain.topleveldomain, where `subdomain.` is the first match and `domain.` is the second match of the first group).