I need a regex pattern to match camel case BEM classes following this structure:
BlockName_elementName-modifierName
I've created this regex to do the job:
([A-Z][a-z0-9]+)+(\_[a-z0-9]+[A-Z0-9]?[a-z0-9]*)?(\-[a-z0-9]+[A-Z0-9]?[a-z0-9]*)?
Examples of strings that should match:
Block
BlockName
BlockNameLonger
BlockName93
BlockName_element
BlockName_elementName
BlockName_elementNameLonger
BlockName_4elementName
BlockName_elementName-modifier
BlockName_elementName-modifierName
BlockName_elementName-modifierNameLonger
BlockName_elementName-modifier567Name
Currently it matches all except the 'longer' strings. I can't work out how to group correctly to match any length of camel case groups. Can anyone help?
See demo here: http://regexr.com/3h0sf