# Can a regular language enforce a length limit AND disallow consecutive characters?

I was reading the venerable "How to Find or Validate an Email Address [using Regex]", and I came across the following statement at the bottom of the page:

[A] true regular language cannot enforce a length limit and disallow consecutive hyphens at the same time.

This seems wrong to me.

I feel like if the length of a string is bounded ahead of time, you should be able to write a DFA which processes pretty much any rule on the input string, as you can just create $n$ states from the most recent states, where $n$ is the number of letters in the alphabet, repeating for the maximal length of the input string?

If this reasoning is wrong, can someone point me in the right direction?

You are not wrong. In fact, any finite language $L$ over a finite alphabet $\Sigma$ is regular. If $L$ is finite, there must be an integer $d$ such that for all $x \in L$ it holds that $|x| \le d$. Let $|\Sigma| = s$ and construct a complete $s$-ary tree of depth $d$, where each edge from a node to one of its children is a transition associated to some $c \in \Sigma$.
We can see that such a tree enumerates all the strings over $\Sigma$ of length at most $d$; this means that each string of $L$ must correspond to some node of the tree. Marking as an accepting state every such node yields a DFA for $L$.
Yeah, that claim looks bogus to me. Regular languages are closed under intersection. The set of all words of length at most $k$ is regular; the set of all words with no consecutive hyphens is regular; so their intersection is regular. Every regular language can be matched by a regular expression.