To make the .+
optional, you could do:
"(?:.+)?";
(?:..)
is called a non-capturing group. It only does the matching operation and it won't capture anything. Adding ?
after the non-capturing group makes the whole non-capturing group optional.
Alternatively, you could do:
".*?";
.*
would match any character zero or more times greedily. Adding ?
after the *
forces the regex engine to do a shortest possible match.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…