文字列に一致する正規表現が必要です
- のような特殊文字で始まり、
[#.>+~]
その後に小文字の ASCII 単語が続くか、または - のような異なる特殊文字のみで構成され
*
ます。
特殊文字はグループ番号 1 に、次の単語 (または 2 番目のケースでは空の文字列) はグループ番号 2 にキャプチャする必要があります。
最初のケースは で処理/^([#\.>+~]?)([a-z]+)$/
できますが、2 番目のケースをこの正規表現に入れて次の結果を得るにはどうすればよいですか。
"#word" -> 1 => "#", 2 => "word"
"~word" -> 1 => "~", 2 => "word"
"##word" -> no match
"+#word" -> no match
"!word" -> no match
"*word" -> no match
"word" -> 1 => "", 2 => "word"
"*" -> 1 => "*", 2 => ""
"**" -> no match
"*word" -> no match