in reply to Re^2: doubt in matching
in thread doubt in matching

thanks for the reply ,actually i want to do the following thing:: any consecutive letters in the word should be enclosed in brackets.for eg: "thhheeee good boyy" should be "t(hhh)(eeee) g(oo)d bo(yy)" . the no of consecutive letters may differ in the word.

Replies are listed 'Best First'.
Re^4: doubt in matching
by Samy_rio (Vicar) on Feb 13, 2006 at 09:40 UTC

    uva, Try the below code,

    use strict; use warnings; $_="thhheeee good boyy"; s/((\w)\2{1,})/\($1\)/gsi; print $_; __END__ t(hhh)(eeee) g(oo)d bo(yy)

    Regards,
    Velusamy R.


    eval"print uc\"\\c$_\""for split'','j)@,/6%@0%2,`e@3!-9v2)/@|6%,53!-9@2~j';

Re^4: doubt in matching
by McDarren (Abbot) on Feb 13, 2006 at 09:47 UTC
    "thhheeee good boyy" should be "t(hhh)(eeee) g(oo)d bo(yy)"
    In that case, maybe you want something like this:
    #!/usr/bin/perl -w use strict; while (<DATA>) { chomp; $_ =~ s/(\w)(\1+)/\($1$2\)/g; print "$_\n"; } __DATA__ thhheeee good boyy the qqquick brrrowwwn fooox
    Output:
    t(hhh)(eeee) g(oo)d bo(yy) the (qqq)uick b(rrr)o(www)n f(ooo)x
    Cheers,
    Darren :)