1

在这里,我正在尝试提取电话号码。来自电子邮件

                        </tr>
                        <tr>
                            <td height=3D"20" valign=3D"bottom" style=3D"font-s=
    ize:10px; color:#817f80;padding:0px;margin:0px;">1-877-435-2623 | Mon-Fri 8=
    am-5pm, Sat-Sun 8am-12pm PST</td>
                        </tr>
                        <tr>
                            <td height=3D"35" valign=3D"bottom" style=3D"font-s=
    ize:10px; margin:0px; margin-top: 10px; padding:0px; padding-bottom:0px; co=
    lor:#939393;">&copy; 2012 Elance, Inc. |  441 Logue Ave. Suite 150 | Mounta=
    in View, CA 94043</td>
                        </tr>
                        <tr>
                            <td height=3D"20" valign=3D"bottom" style=3D"font-s=
    ize:10px; margin:0px; margin-bottom:25px; padding:0px; color:#939393;"><a h=
    ref=3D"https://www.elance.com/q/legal"><span style=3D"color:#939393;text-de=
    coration:none;">Terms of Service</span></a> | <a href=3D"https://www.elance=
    .com/p/legal/privacy-policy.pdf"><span style=3D"color:#939393;text-decorati=
    on:none;">Privacy Policy</span></a> | All Rights Reserved.</td>
                        </tr>
                    </table>
                    <div style=3D"margin: 0; padding: 0;">
                        <a href=3D"http://www.facebook.com/elance"><img src=3D"=
    https://www.elance.com/images/4.0/referral/facebook-btn-16x16.png" border=
    =3D"0" alt=3D"Facebook" title=3D"Facebook" /></a>&nbsp;
                        <a href=3D"http://www.twitter.com/elance"><img src=3D"h=
    ttps://www.elance.com/images/4.0/referral/twitter-btn-16x16.png" border=3D"=
    0" alt=3D"Twitter" title=3D"Twitter" /></a>&nbsp;
                        <a href=3D"http://www.linkedin.com/company/elance"><img=
     src=3D"https://www.elance.com/images/4.0/nav/nav_logo_sprite/icon-li.gif" =
    border=3D"0" alt=3D"LinkedIn" title=3D"LinkedIn" /></a>&nbsp;
                        <a href=3D"http://www.youtube.com/elance"><img src=3D"h=
    ttps://www.elance.com/images/4.0/nav/nav_logo_sprite/icon-yt.gif" border=3D=
    "0" alt=3D"Youtube" title=3D"Youtube" /></a>
                    </div>
                </td>0345-5407008
345-5124587
124-541-2215
+92-3455412412
3251452114
009124125413
hello world its my no. 03005134012
            </tr>

            </tbody>
        </table>

    </DIV>

    </BODY>
    </HTML>




    --PHP-alt-3fbbc9acbecd103566642de6249238ea--

    --PHP-mixed-3fbbc9acbecd103566642de6249238ea--


    251254125

使用正则表达式

 ?(\d|\+)(\+|\d|\(|\)|-| |\.){7,25} ?

但我想忽略在这些字符串中找到的匹配项

--PHP-alt-3fbbc9acbecd103566642de6249238ea--

--PHP-mixed-3fbbc9acbecd103566642de6249238ea--

试试http://rubular.com/r/b6K0LOcn3N 任何更好的正则表达式???
对我的正则表达式的解释:?(\d|\+)(\+|\d|\(|\)|-| |\.){7,25} ?

  1. 开始抓不。仅在检测到空格或非空格时。
  2. 如果 first 是 0-9 或 + 匹配 (+|\d|(|)|-| |.) 中的任何字符,则开始匹配
  3. 7,25 因为电话号码的迷你长度。是 7 并且
  4. 最多约 25 个,包括空格和 - 等
4

1 回答 1

1

尝试使用一些单词边界\b

(?:\b\d|\+)(?:\+|\d|\(|\)|-| |\.){7,25}\b

我把捕获组变成了非捕获组。如果您只需要整数,我认为您不需要捕获组。

\b当有一个“单词”字符后跟一个“非单词”字符时匹配,反之亦然(即要么\w\W\W\w)。

正则表达式 101 演示

于 2013-09-17T09:00:04.363 回答