Popcorn Dave has asked for the wisdom of the Perl Monks concerning the following question:
I am trying to figure out what kind of regex would replace the 4th space in a line of data with \n.
I'm working with name and address data and printing them to a PDF file to print on labels. However, some of the names are spanning in to the next column of labels. My thought was to replace the 4th instance of \s with \n so that:
School of Wisdom and Knowledge College Preparatory <PR> would become
School of Wisdom and
Knowledge College Preparatory
All I could think to do, as a regex, was to:
$name =~ s/.+\s.+\s.+\s.+\s/.+\s.+\s.+\s.+\n/;
but that got nowhere at all.
Is it even possible to count the number of matches in a regex without using some kind of loop? Is it even possible to replace on the 4th occurence of something inside a regex at all?
Thanks in advance!
Some people fall from grace. I prefer a running start...
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Need help with regex to replace 4th \s with \n in data line
by japhy (Canon) on Sep 05, 2002 at 23:22 UTC | |
|
Re: Need help with regex to replace 4th \s with \n in data line
by Django (Pilgrim) on Sep 05, 2002 at 23:49 UTC | |
by Popcorn Dave (Abbot) on Sep 06, 2002 at 05:11 UTC | |
|
Re: Need help with regex to replace 4th \s with \n in data line
by sauoq (Abbot) on Sep 05, 2002 at 23:05 UTC | |
|
Re: Need help with regex to replace 4th \s with \n in data line
by jmcnamara (Monsignor) on Sep 05, 2002 at 23:38 UTC | |
|
Re: Need help with regex to replace 4th \s with \n in data line
by zigdon (Deacon) on Sep 05, 2002 at 23:10 UTC | |
|
Re: Need help with regex to replace 4th \s with \n in data line
by Popcorn Dave (Abbot) on Sep 05, 2002 at 23:28 UTC | |
|
Re: Need help with regex to replace 4th \s with \n in data line
by fglock (Vicar) on Sep 06, 2002 at 14:53 UTC |