On Sat, 6 May 2017 23:13:04 +0200
David Emanuel da Costa Santiago <deman...@gmail.com> wrote:
> Is there any regular expression, that can match any consecutive
> character?

You want to use a back-reference - e.g. /(.)\1+/ matches any character
followed by one or more of that same character.

Demo:

[davidp@cloudburst:~/tmp]$ cat re-repeat.pl 
#!/usr/bin/env perl

use strict;

for my $string (qw(qwerty qwertyq qqwerty qwerrrty)) {
    say "$string " .  ($string =~ /(.)\1+/ ? "contains" : "has no")
        . " repeated characters";
}

[davidp@cloudburst:~/tmp]$ perl re-repeat.pl
qwerty has no repeated characters
qwertyq has no repeated characters
qqwerty contains repeated characters
qwerrrty contains repeated characters

For further info, a read of perlretut should help:
https://perldoc.perl.org/perlretut.html#Backreferences

Cheers

Dave P (bigpresh)

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to