I don't think you can use regex for the first case. The second case is easy though:
Pattern pattern = Pattern.compile("([a-z\d])\1\1", Pattern.CASE_INSENSITIVE);
Since \1
represents part matched by group 1
this will match any sequence of three identical characters that are either within the range a-z
or are digits (d
).
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…