If I understand you correctly you want to make sure that both xx-yy
belong to same category (alphabetic, numeric). In case they are place xx
in group 1 and yy
in group 2.
If that is true then you can use look-ahead to test if string is in form you want to accept, and then place each part in separate groups.
This should do what you want:
(?i)^(?=[a-z]+-[a-z]+$|d+-d+$)([a-zd]+)-([a-zd]+)$
DEMO
Short explanation
^(?=[a-z]+-[a-z]+$|d+-d+$)
this look-ahead tests if entire string is in form
alpha-alpha
- OR
numeric-numeric
([a-zd]+)-([a-zd]+)$
if lest previously performed by look-ahead was positive we can place matched characters (regardless if they are a-z
or d
- this was tested previously) to group 1 and group 2.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…