I think it is fine to have a bunch of small steps rather than a single super regex. One thing to consider is that these scraped webpage "fixer" regex'es need to be modified all the time. You'll come across more goofy stuff further down the road - so try to be flexible. Performance is usually not a factor at all.

My approach below. If split could work starting from right to left instead of the other way round, I'd use it! But alas it doesn't do that! Below I worked from right to left and used \S (non-space) and \s (space) Perl short-cuts. I think it is fine to use a combination of "fixing" and regex "splitting". In the case as explained so far, it is certainly possible to do everything in one regex. But, you've already seen the value in changing the tabs to | characters so that you can see them and print. Sometimes these intermediate steps work out to be real handy for debugging!

#!/usr/bin/perl -w use strict; my @tests = ( 'A ||118|AVIANN GILDED WILD HONEY. HM 75081701. 02-04-97', 'A ||118|||AVIANN GILDED &^$WILD HONEY HP--09090901. 02-04-97', ); foreach my $test (@tests) { $test =~ s/^.*\|//; #remove beginning til last | #"fix" possible typo in the registration number # HP--09090901. becomes HP 09090901. $test =~ s/(\w+)[-]+([\d.]+\s+\S+)$/$1 $2/; my ($name,$number,$date) = $test =~ m/^(.*)\s+(\S+\s+\S+)\s+(\S+)$/ +; $number =~s/\.$//; #fix possible typo trailing '.' print "\n name=$name\n number=$number\n date=$date\n"; } __END__ name=AVIANN GILDED WILD HONEY. number=HM 75081701 date=02-04-97 name=AVIANN GILDED &^$WILD HONEY number=HP 09090901 date=02-04-97

In reply to Re: regexp identify variable number of digits within a sentence by Marshall
in thread regexp identify variable number of digits within a sentence by bdalzell

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.