regex - regular expression to match repeated characters? -
i'm looking perl
regular expression match strings made of same letters.
it should match aa
, aaa
, aaaa
, aaaaa
, on, not aabb
, abba
, aaab
, aaaabaa
, on.
i know can use \1
refer first character /(.)\1/
, match aabb
. advice?
this seems work me:
/^(.)\1*$/
the ^
character matches beginning of string, , $
matches end.
the whole expression can translated into: "at beginning of string, match character, followed number of same character, followed end of string.
Comments
Post a Comment