in reply to Beginner question about search and replace
As moritz explained you were matching every pair of numbers when you wanted every number with a space following it.
Another way to replace every space following a number with a semicolon could be *(untested):
s/(\d)(?:\s+)/$1;/gThe \d matches any single digit and is the same as [0-9]. As you learned in your attempt, the parentheses 'capture' that match and store it in memory so we can use it later. The second part of our match looks for at least one space following that digit but doesn't store it in memory because of the (?: ) since we're not planning on using it to help build our replace pattern.
Aside from the perldocs on regexes, if you're interested, you might like Mastering Regular Expressions by Jeffrey E.F. Friedl and/or Data Munging with Perl by Dave Cross.
| UPDATE | |
|---|---|
| Same day, 16.Sep.2011 :: 02:35:24 PM :: | Changed: s/(\d)(?:\s)+/$1;/g To : s/(\d)(?:\s+)/$1;/g Following AnomalousMonk's suggestion. |
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Beginner question about search and replace
by Kc12349 (Monk) on Sep 16, 2011 at 15:32 UTC | |
by luis.roca (Deacon) on Sep 16, 2011 at 15:45 UTC | |
by Kc12349 (Monk) on Sep 16, 2011 at 16:46 UTC | |
by AnomalousMonk (Archbishop) on Sep 16, 2011 at 18:30 UTC |