沿(不要忘了对Unicode正则表达式的 “U” 标志)线:
^(?:\*\*)?(?=[^*]{4,})(\p{Lu}+)(?:\s*-\s*(\p{Lu}+))?(?:\*\*)?\s*$
^ # start of line
(?:\*\*)? # two stars, optional
(?=[^*]{4,}) # followed by at least 4 non-star characters
(\p{Lu}+) # group 1, Unicode upper case letters
(?: # start no capture group
\s*-\s* # space*, dash, space*
(\p{Lu}+) # group 2, Inicode upper case letters
)? # end no capture group, make optional
(?:\*\*)? # two stars, optional
\s* # optional trailing spaces
$ # end of line
编辑:简化,因为每个评论:
^(?=[A-Z ]{4,})([A-Z ]+)(?:-([A-Z ]+))?\s*$
^ # start of line
(?=[A-Z -]{4,}) # followed by at least 4 upper case characters, spaces or dashes
([A-Z ]+) # group 1, upper case letters or space
(?: # start no capture group
- # a dash
([A-Z ]+) # group 2, upper case letters or space
)? # end no capture group, make optional
\s* # optional trailing spaces
$ # end of line
组1和2的内容必须在使用前修剪。