Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: How to avoid the duplication in a string

by ccn (Vicar)
on Oct 22, 2008 at 11:00 UTC ( [id://718696]=note: print w/replies, xml ) Need Help??


in reply to How to avoid the duplication in a string

$a =~ s/(.)\1+/$1/g;

Replies are listed 'Best First'.
Re^2: How to avoid the duplication in a string
by soubalaji (Sexton) on Oct 22, 2008 at 11:10 UTC
    could you please explain what is the meaning for \1+ in perl
      could you please explain what is the meaning for \1+ in perl

      In regular expressions, backslashed numeric digits are references back to the preceding captures. So \1 refers to the same thing that was captured in the first set of parentheses, and \2 refers to the same thing that was captured in the second set, and so forth.

      As for the +, it modifies a backreference in exactly the same way it modifies any other atom in a regular expression.

      -- 
      We're working on a six-year set of freely redistributable Vacation Bible School materials.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (6)
As of 2024-04-24 10:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found