On Sep 7, Dan said: >If I have a string with say a number of '>>>>>>' in it which may be >variable in length and I wish to write a regexp to match and replace it >with the equivalent number of ')'s [ie >>>> would become ))))] There's a very clever solution to this in "Effective Perl Programming". It is specifically for LEADING zeroes: s/\G0/ /g; That turns all leading zeroes in $_ to spaces. Yours might not be leading, so you must first "prep" your string: /[^>]*/g; # set pos($_) to right before the first >, if there is one s/\G>/)/g; # change all consecutive >'s from this point on to )'s That will work. You can also do: s/(>+)/")" x length($1)/g; That one probably works better, too -- it finds ALL runs. You'd have to massage that first approach quite a bit to get it to work this way. -- Jeff "japhy" Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/ RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/ ** Look for "Regular Expressions in Perl" published by Manning, in 2002 ** -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: general multipliers in a substitution regexp..
Jeff 'japhy/Marillion' Pinyan Fri, 07 Sep 2001 08:52:35 -0700
- general multipliers in a substitution regexp... Dan
- RE: general multipliers in a substituti... Jeff 'japhy/Marillion' Pinyan
- RE: general multipliers in a substituti... pconnolly
- RE: general multipliers in a substituti... Jeff 'japhy/Marillion' Pinyan
- RE: general multipliers in a substi... Jeff 'japhy/Marillion' Pinyan
- RE: general multipliers in a substi... Dan