I'm new to Perl, and am under the gun to get something figured out. If you'd like to increase your karma, help a novice out.

I need to parse phone numbers from a database. Since there was no input validation in the first place, all kinds of crazy things are in there. To wit:

(555) 555-5555
555.555.5555
555-555-5555
(555)555.5555

Here's where it gets fun:
(555) 555-5555 x.555
555.555.5555 Ext. 555
555-555-5555 ext.555

And so on.

My database has a table for phone numbers which has, among other fields, one for the number (tbl_phone.number), and one for the extension (tbl_phone.extension). It seems like what I want to do to grab this data is to put the first 7 things that are digits into $1, and anything that follows that is a digit into $2. This allows me to stuff $1 into tbl_phone.number using a standardized format, as well as putting $2 into tbl_phone.extension with numerals only.

The trouble is that I do not have much experience with regular expressions, so I am reading the camel and ram books to figure it out.

Thanks in advance. I really appreciate the help.

/Scott

In reply to Simple Regex by sevrin

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.