One thing that you need to keep in mind when building regexes like these is the subject of greedy. By default, the regex will (“greedily ...”) find the longest available string that matches. You can specify that it should, instead, opt for the shortest one, and sometimes (depending on the nature of the string that is to be processed) you must do that.
I also strongly advocate that your programming should be suspicious of its input files. If you expect 5 strings, check each time that you have them. In short, if you can be certain of anything in the correctly-running program given correct data, “be from MIssouri ... show me.” Quite frankly, most of the time, I’ve encountered broken data. The supplier of the data didn’t know it was broken. “Inexplicable bugs” turned out to be from that cause. Only the computer itself is in the necessary position to recognize the existence of these issues ... take the slight extra time to make it do so.
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:
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.
| & || & |
| < || < |
| > || > |
| [ || [ |
| ] || ] ||