$re = '/^((u|is|has)\-[a-z0-9][a-zA-Z0-9]*|([A-Z][a-zA-Z0-9]*(__[a-z0-9][a-zA-Z0-9]*)?(--[a-z0-9][a-zA-Z0-9]*)?))$/m';
$str = 'is-state
is-State
is-stateActive2
u-utility
u-Utility
u-utilityClass2
has-child
has-Child
has-childClass2
his-child
a-child
1-child
A-child
js-test
Block
Block--mod
Block__el
Block__el--mod
BlockBox
BlockBox--modMod
BlockBox__elEl
BlockBox__elEl--modMod
block-box
Block-box
blockBox
5block
B__m--e
B__M--E
B__m--E
B__M--e
b__M--E
b__m--E
b__M--e
b__m--e
B__m__e
B--m--e
B--m__e
B_m-e
B-m_e
';
preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0);
// Print the entire match result
var_dump($matches);
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for PHP, please visit: http://php.net/manual/en/ref.pcre.php