From: "David A. Black" Date: 2008-12-15T03:40:55+09:00 Subject: Re: Help with an "easy" regular expression substitution --1926193751-1458768965-1229280498=:27349 Content-Type: MULTIPART/MIXED; BOUNDARY="1926193751-1458768965-1229280498=:27349" This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. --1926193751-1458768965-1229280498=:27349 Content-Type: TEXT/PLAIN; charset=X-UNKNOWN; format=flowed Content-Transfer-Encoding: QUOTED-PRINTABLE Hi -- On Mon, 15 Dec 2008, I=C3=B1aki Baz Castillo wrote: > Hi, I'm getting crazy to get a theorically easy substitution: > > I've a file with a header: > X-Level: *** > where the number of "*" is variable (from 0 up to 10). > > And I just want to replace "*" by "X", so get: > X-Level: XXX > > I don't get it since I don't know how to replace ANY number of "*" with t= he > same number of "X" just in the header "X-Level". > > Any help? Thanks a lot. The first thing that comes to mind: text.sub(/(X-Level: )(\*+)/) { $1 + 'X' * $2.size } or, in Oniguruma, using look-behind: text.sub(/(?<=3DX-Level: )(\*+)/) { 'X' * $1.size } David --=20 David A. Black / Ruby Power and Light, LLC Ruby/Rails consulting & training: http://www.rubypal.com Coming in 2009: The Well-Grounded Rubyist (http://manning.com/black2) --1926193751-1458768965-1229280498=:27349-- --1926193751-1458768965-1229280498=:27349--