Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^3: doubt in matching

by uva (Sexton)
on Feb 13, 2006 at 09:20 UTC ( [id://529763]=note: print w/replies, xml ) Need Help??


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 :)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://529763]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (5)
As of 2025-01-22 12:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Which URL do you most often use to access this site?












    Results (63 votes). Check out past polls.