Fellow monks,
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...
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.