Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
I have pipe delimited text data and I want to ensure that there is a at least one spaces between each pipe (I don't want to add any spaces to fields containing data). E.g., what I want is:
My current code looks like this:| | | | | | | | |red| | |blue| | |green| |
and produces the following output:use strict; while (<DATA>) { s/\|\|/\| \|/g; print; } __DATA__ ||||| ||||red|| |blue|||green||
I realize that I can just execute the regex twice to get the desired results but that seems ugly. There must be something simple that I'm overlooking or don't understand. Any hints or pointers welcome. Thanks.| || || | || |red| | |blue| ||green| |
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Regex Backtracking
by Joost (Canon) on Jun 12, 2002 at 16:31 UTC | |
by Anonymous Monk on Jun 12, 2002 at 16:45 UTC | |
|
Re: Regex Backtracking
by frankus (Priest) on Jun 12, 2002 at 17:00 UTC | |
|
Re: Regex Backtracking
by codine (Initiate) on Jun 12, 2002 at 16:58 UTC |