Got more questions? Find advice on: ASP | SQL | XML | Windows
in Search
Welcome to RegexAdvice Sign in | Join | Help

Area Code separate from Phone Number - concatenation

Last post 06-16-2011, 11:59 PM by jwb4273. 0 replies.
Sort Posts: Previous Next
  •  06-16-2011, 11:59 PM 83268

    Area Code separate from Phone Number - concatenation

    Hello all,

    I am trying to get an expression to do the following:

    1) Match regular 10 digit US phone number

    2) Match 10 digit US phone number with a 1 or +1 in front (including country code)

    3) Recognize a 7 digit number and grab the area code from the previous table cell.

     

    I've been able to piece together several separate regex strings to do certain pieces of this, but I can not figure out how to piece them together completely.

    1 and 2 are handled by :  \+?(1[\s-.]?)?((\(\d{3}\))|(\d{3}))[\s.\-]?\d{3}[\s.\-]?\d{4}

     

    For 3, I've been able to make a regex identify the <td> cells by using

     (?:<td>|<td [^<]+?>)[\d\w\s\-]*((?!</td>).)*</td>

     

    and been able to find either the area code or 7 digit number by using

     (\d{3}|[\s.\-]?\d{4}) 

     

    However, I can not make those latter 2 mesh up as necessary.

     

    The sample HTML code for the last case is:

    <td id="wStr120Re_tab_re_tabpage_p_dw_p_grid_tbl_td_0_6">

    TEXT

    </td>

    <td id="wStr120Re_tab_re_tabpage_p_dw_p_grid_tbl_td_0_7" class="center_align">

    TEXT

    </td>

    <td id="wStr120Re_tab_re_tabpage_p_dw_p_grid_tbl_td_0_8" class="center_align">

    512 <<< Areacode

    </td>

    <td id="wStr120Re_tab_re_tabpage_p_dw_p_grid_tbl_td_0_9" class="center_align">

    111-2222 <<<< 7 digit phone number

    </td> 

     

    Ideally, the output from all 3 cases would be the complete 10 digit number. (the first 2 are obviously easy, the third it has to concatenate). 

    Any assistance would be helpful! Thank you! 

     

     

View as RSS news feed in XML