Get all pairs of same consecutive characters from string?
str = "AabHHioPjggtYuggbwq";
StringCases[str, x_ ~~ x_, IgnoreCase -> True]
{"Aa", "HH", "gg", "gg"}
Or in the generalized version of the question:
str = "AaAbHHhhhioPjggtYuggGgGbwq";
StringCases[str, x_ ~~ (x_) .., IgnoreCase -> True]
{"AaA", "HHhhh", "gg", "ggGgG"}
getpairs[str_String] := StringJoin @@@ Select[
Partition[Characters[str], 2, 1],
SameQ @@ ToUpperCase[#] &]
str = "AabHHioPjggtYuggbwq";
getpairs[str]
(* {"Aa", "HH", "gg", "gg"} *)
I will give a RegularExpression
version here.
str = "AabHHioPjggtYuggbwq";
StringCases[str, RegularExpression["(?i)(\\w)\\1"]]
{"Aa", "HH", "gg", "gg"}
Per this comment,that the string contain 3 or more letter case
str = "aAabHhHioPjggtYuggbwwq";
StringCases[str, RegularExpression["(?i)(\\w)\\1+"]]
{"aAa", "HhH", "gg", "gg", "ww"}