if case doesn't matter, depending on the language you're using, you can probably get away with this
^[\w:-]+ \. [\w:-]+$
\w
matches [A-Za-z0-9_]
An alternative would be to build the RegExp from strings. Here's a JavaScript example
var chars = '[\\w:-]';
var re = new RegExp('^' + chars + ' \\. ' + chars + '$');
re;
// => /^[\w:-] \. [\w:-]$/
This contrived example doesn't save you much, but depending on how complex your regexen can get, this could save you from having to duplicate your character classes. Also, don't forget to \\
escape your slashes when building a regexp with a string.
If I was writing a parser or something, I would probably take the above example one step further and do something like this:
RegExp.build = function(regexen, flags) {
return new RegExp(regexen.map(function(re) { return re.source }).join(''), flags);
};
var chars = /[\w:-]+/;
RegExp.build([/^/, chars, / \. /, chars, /$/], 'gi');
//=> /^[\w:-]+ \. [\w:-]+$/gi