如何使用REGEXEXTRACT正则表达式从Google电子表格中提取数据

时间:2017-05-02 05:50:41

标签: regex excel spreadsheet

以下是从电子邮件中检索到的代码。这包含两个主要信息,应该提取到Google电子表格中的其他单元格。

<div dir="ltr"><br><br><div class="gmail_quote"><div dir="ltr">---------- Forwarded message ---------<br>From: Jakmall &lt;<a href="mailto:support@jakmall.com">support@jakmall.com</a>&gt;<br>Date: Sat, Apr 29, 2017 at 9:32 PM<br>Subject: Pesanan 1610661095-28751834610 telah dikirim oleh penjual<br>To: Hari Anggara &lt;<a href="mailto:harianggaraa@gmail.com">harianggaraa@gmail.com</a>&gt;<br></div><br><br><u></u>








<div style="height:100%!important;width:100%!important;margin:0;padding:0"> <table border="0" cellpadding="0" cellspacing="0" width="100%" style="border-collapse:collapse!important"><tbody><tr>
<td bgcolor="#ffffff" align="center" width="100%" style="font-family:niveau,Arial,sans-serif;line-height:1.5;font-size:14px;color:#4d485f;padding:10px 15px 10px 15px" class="m_1160478122239317640section-header"> <div style="display:none;font-size:1px;color:#fefefe;line-height:1px;font-family:Helvetica,Arial,sans-serif;max-height:0px;max-width:0px;opacity:0;overflow:hidden">  Bogesi Dompet Kulit Pria - ... 1 barang lainnya  </div> <table border="0" cellpadding="0" cellspacing="0" width="500" class="m_1160478122239317640wrapper" align="center" style="border-collapse:collapse!important"><tbody><tr>
<td align="center" style="font-family:niveau,Arial,sans-serif;line-height:1.5;font-size:14px;color:#4d485f"> <table border="0" cellpadding="0" cellspacing="0" width="100%" style="border-collapse:collapse!important"><tbody><tr>
<td bgcolor="#ffffff" align="center" style="font-family:niveau,Arial,sans-serif;line-height:1.5;font-size:14px;color:#4d485f"><a href="https://www.jakmall.com" style="text-decoration:none" target="_blank"><img alt="Jakmall.com" src="https://ci3.googleusercontent.com/proxy/80kPRniWjNGtIVTcUyCuJJda8P3yLS6LKc_YNFYgQBYpGnRt2-jlwe-YJow7nrQSyY0stEX4swxBM0Lw_oYhSXcn-JBtaV_DYq5eoFo=s0-d-e1-ft#https://www.jakmall.com/images/desktop/logo@2x-beta.png" width="180" style="border:0;height:auto;line-height:100%;outline:none;text-decoration:none;display:block;font-family:Helvetica,Arial,sans-serif;color:#666666;font-size:16px" border="0"></a></td> </tr></tbody></table>
</td> </tr></tbody></table>
</td> </tr></tbody></table>
<table border="0" cellpadding="0" cellspacing="0" width="100%" style="border-collapse:collapse!important"><tbody><tr>
<td bgcolor="#f6f6f7" align="center" style="font-family:niveau,Arial,sans-serif;line-height:1.5;font-size:14px;color:#4d485f;padding:30px 15px 20px 15px" class="m_1160478122239317640section-padding"> <table border="0" cellpadding="0" cellspacing="0" width="500" class="m_1160478122239317640responsive-table" style="border-collapse:collapse!important"><tbody><tr>
<td style="font-family:niveau,Arial,sans-serif;line-height:1.5;font-size:14px;color:#4d485f"> <table width="100%" border="0" cellspacing="0" cellpadding="0" style="border-collapse:collapse!important">
<tbody><tr>
<td style="font-family:niveau,Arial,sans-serif;line-height:1.5;font-size:14px;color:#4d485f"> <table width="100%" border="0" cellspacing="0" cellpadding="0" style="border-collapse:collapse!important"><tbody><tr>
<td align="center" style="font-size:22px;line-height:30px;font-family:Arial,sans-serif;color:#ff2179;padding-top:10px;padding-bottom:20px;font-weight:300">Pesanan Anda telah dikirim</td> </tr></tbody></table>
</td> </tr>
<tr>
<td align="center" style="font-size:16px;line-height:24px;font-family:&#39;Proxima Nova&#39;,Helvetica,Arial,sans-serif;color:#666666;font-weight:normal;padding-top:10px;padding-bottom:10px;text-align:center" class="m_1160478122239317640padding-copy"> Hai Hari Anggara, Pesanan Anda sedang dikirim menuju alamat tujuan. </td> </tr>
<tr>
<td style="font-family:niveau,Arial,sans-serif;line-height:1.5;font-size:14px;color:#4d485f"> <table width="100%" border="0" cellspacing="0" cellpadding="0" style="border-collapse:collapse!important"><tbody><tr>
<td align="center" style="background:white;padding:15px 20px 15px 20px;font-size:14px;line-height:22px;font-family:&#39;Proxima Nova&#39;,Helvetica,Arial,sans-serif;color:#666666;border-right:1px solid #ddd" class="m_1160478122239317640padding-copy"> Kode Pesanan <br><strong style="color:black;font-size:16px"> 28751834610 </strong> </td> <td align="center" style="background:white;padding:15px 20px 15px 20px;font-size:14px;line-height:22px;font-family:&#39;Proxima Nova&#39;,Helvetica,Arial,sans-serif;color:#666666" class="m_1160478122239317640padding-copy"> No. Resi Jne <br><strong style="color:black;font-size:16px"> 0110871702023376 </strong> </td> </tr></tbody></table>
</td> </tr>
<tr>
<td align="center" style="font-size:16px;line-height:24px;font-family:&#39;Proxima Nova&#39;,Helvetica,Arial,sans-serif;color:#666666;font-weight:normal;padding-top:20px"> Anda dapat melacak status pengiriman dengan mengklik tombol di bawah ini : </td> </tr>
<tr>
<td style="font-family:niveau,Arial,sans-serif;line-height:1.5;font-size:14px;color:#4d485f"> <table width="100%" border="0" cellspacing="0" cellpadding="0" style="border-collapse:collapse!important"><tbody><tr>
<td align="center" style="font-family:niveau,Arial,sans-serif;line-height:1.5;font-size:14px;color:#4d485f;padding:25px 0 20px 0" class="m_1160478122239317640padding-copy"> <table border="0" cellspacing="0" cellpadding="0" class="m_1160478122239317640responsive-table" style="border-collapse:collapse!important"><tbody><tr>
<td align="center" style="font-family:niveau,Arial,sans-serif;line-height:1.5;font-size:14px;color:#4d485f"><a href="https://www.jakmall.com/member/purchase-history/shipment?ph_keywords=28751834610" style="font-size:16px;font-family:&#39;Proxima Nova&#39;,Helvetica,Arial,sans-serif;font-weight:bold;color:#ffffff;text-decoration:none;background-color:#ff2179;border-top:13px solid #ff2179;border-bottom:13px solid #ff2179;border-left:45px solid #ff2179;border-right:45px solid #ff2179;display:inline-block" class="m_1160478122239317640mobile-button" target="_blank">Lacak Status Pengiriman</a></td> </tr></tbody></table>
</td> </tr></tbody></table>
</td> </tr>
</tbody></table>
</td> </tr></tbody></table>
</td> </tr></tbody></table>
<table border="0" cellpadding="0" cellspacing="0" width="100%" style="border-collapse:collapse!important"><tbody><tr>
<td bgcolor="#fff" align="center" style="font-family:niveau,Arial,sans-serif;line-height:1.5;font-size:14px;color:#4d485f;padding:20px 15px 0 15px"> <table border="0" cellpadding="0" cellspacing="0" width="500" class="m_1160478122239317640responsive-table" style="border-collapse:collapse!important"><tbody><tr>
<td style="font-family:niveau,Arial,sans-serif;line-height:1.5;font-size:14px;color:#4d485f"> <table width="100%" border="0" cellspacing="0" cellpadding="0" style="border-collapse:collapse!important">
<tbody><tr>
<td style="line-height:1.5;font-size:16px;font-family:Arial,sans-serif;color:#000;font-weight:bold;text-align:left"> Pesanan Anda </td> </tr>
<tr>
<td style="font-size:11px;line-height:16px;font-family:Arial,sans-serif;color:#444;font-weight:normal;text-align:left"> <table width="100%" border="0" cellspacing="0" cellpadding="0" style="border-collapse:collapse!important"><tbody><tr>
<td style="line-height:1.5;font-size:13px;font-family:Arial,sans-serif;color:#000;font-weight:bold;text-align:left;border-bottom:1px solid #ddd;padding-top:20px;padding-bottom:5px"> Pesanan 28751834610 </td> </tr></tbody></table>
<table width="100%" border="0" cellspacing="0" cellpadding="0" style="border-collapse:collapse!important">
<tbody><tr>
<td valign="top" align="left" style="font-family:niveau,Arial,sans-serif;line-height:1.5;font-size:14px;color:#4d485f;text-align:left;width:40px;padding:10px 10px 10px 0"> <a href="https://www.jakmall.com/fast-n-cheap/bogesi-dompet-kulit-pria-bogesi836#7585078351985" style="text-decoration:none" target="_blank"> <img src="https://ci6.googleusercontent.com/proxy/J2qDv_lzFu9F_m2UISCjTCETfBEVFVyWba6YSbfCPS2m_D3pqMzUht_jZcSN6ITxom2P34nN_J67rMU3TOajwzYm2MFLBEaHkcFLNqPA_jCUP-To1eYIumbpEAX4C_-mx8y7WjNCZpgcyvgjNXCFwLN-MQaWKvm_iWEolQzfnRGTuBIVYYTivQfN9tuOWE6SwbhGi7d9QPkP7taRA5f_9Q1iQk4ZCMhPd14lAYFGw730vpc=s0-d-e1-ft#https://jakmall.id/images/products/ba3159/thumbnail/bogesi-dompet-kulit-pria-short-paragraph-leather-wallet-bogesi836.jpg?s=0cd9b479f5c322a9afc2a90441a46e8b" alt="" width="40" style="border:0;height:auto;line-height:100%;outline:none;text-decoration:none"></a> </td> <td valign="top" align="left" style="font-family:niveau,Arial,sans-serif;font-size:14px;color:#4d485f;text-align:left;padding:10px 0;line-height:18px"> <span style="font-size:12px"> <a href="https://www.jakmall.com/fast-n-cheap/bogesi-dompet-kulit-pria-bogesi836#7585078351985" style="text-decoration:none" target="_blank">Bogesi Dompet Kulit Pria - BOGESI836</a> </span> <br><span style="color:#4d485f;border:1px solid #b8b6bf;border-radius:3px;padding:2px 3px">Hitam</span>  <br><span style="color:#94919f"> 150gr  |  <a href="https://www.jakmall.com/fast-n-cheap" style="text-decoration:none" target="_blank"> Fast n Cheap </a>  </span>  <br><span style="color:#b8b6bf">Catatan:</span> <br><span style="color:#4d485f">cek jangan ada cacat/rusak pastikan oke semua</span>  </td> <td valign="top" align="right" style="font-size:12px;line-height:18px;font-family:Arial,sans-serif;color:#444;text-align:right;white-space:nowrap;padding:10px;padding-right:0"> Rp 44.600 x 1 </td> <td valign="top" align="right" style="font-size:12px;line-height:18px;font-family:Arial,sans-serif;color:#444;text-align:right;width:100px;padding:10px"> Rp 44.600 </td> </tr>
<tr>
<td valign="top" align="left" style="font-family:niveau,Arial,sans-serif;line-height:1.5;font-size:14px;color:#4d485f;text-align:left;width:40px;padding:10px 10px 10px 0"> <a href="https://www.jakmall.com/fast-n-cheap/bogesi-dompet-kulit-pria-bogesi836#8855506689910" style="text-decoration:none" target="_blank"> <img src="https://ci6.googleusercontent.com/proxy/3Hh1fWp1r0ULlJpXkNxM5l-hphqUiRAOVQJcPB3MNxe-YdEaT-6H6y9z4HAWsmu3pXEF_w1J2SfWbNNoOJzGlSIFVLx7lrmAcYj7Jw6BbkcgNBICIAKPSZjfuJJvYklnOZzeCs1Ly2jQYoo27BR6L2pJF0b82tGEw9a4LVglThjHuJ1DoyXp164HJs_XJT-6178l2z8tUB2ZTPTO9r3U7SUF8El4X0p0AbkzvMsja1skkgc=s0-d-e1-ft#https://jakmall.id/images/products/f1193c/thumbnail/bogesi-dompet-kulit-pria-short-paragraph-leather-wallet-bogesi836.jpg?s=41bdb8ce1658c67958205fbb6a1fd376" alt="" width="40" style="border:0;height:auto;line-height:100%;outline:none;text-decoration:none"></a> </td> <td valign="top" align="left" style="font-family:niveau,Arial,sans-serif;font-size:14px;color:#4d485f;text-align:left;padding:10px 0;line-height:18px"> <span style="font-size:12px"> <a href="https://www.jakmall.com/fast-n-cheap/bogesi-dompet-kulit-pria-bogesi836#8855506689910" style="text-decoration:none" target="_blank">Bogesi Dompet Kulit Pria - BOGESI836</a> </span> <br><span style="color:#4d485f;border:1px solid #b8b6bf;border-radius:3px;padding:2px 3px">Coffee</span>  <br><span style="color:#94919f"> 150gr  |  <a href="https://www.jakmall.com/fast-n-cheap" style="text-decoration:none" target="_blank"> Fast n Cheap </a>  </span>  <br><span style="color:#b8b6bf">Catatan:</span> <br><span style="color:#4d485f">cek jangan ada cacat/rusak pastikan oke semua</span>  </td> <td valign="top" align="right" style="font-size:12px;line-height:18px;font-family:Arial,sans-serif;color:#444;text-align:right;white-space:nowrap;padding:10px;padding-right:0"> Rp 44.600 x 1 </td> <td valign="top" align="right" style="font-size:12px;line-height:18px;font-family:Arial,sans-serif;color:#444;text-align:right;width:100px;padding:10px"> Rp 44.600 </td> </tr>
</tbody></table>
<table width="100%" border="0" cellspacing="0" cellpadding="0" style="border-collapse:collapse!important"><tbody><tr>
<td valign="middle" align="left" style="font-family:niveau,Arial,sans-serif;line-height:1.5;font-size:14px;color:#4d485f;padding:10px;text-align:left;background:#f3f3f3"> 0.3kg    |   Dikirim oleh  Jakmall (DKI Jakarta) via Jne REG </td> <td valign="middle" align="right" style="font-family:niveau,Arial,sans-serif;line-height:1.5;color:#4d485f;padding:10px;text-align:right;background:#f3f3f3;font-weight:bold;font-size:12px"> Rp 40.000 </td> </tr></tbody></table>
</td> </tr>
<tr>
<td style="font-size:11px;line-height:16px;font-family:Arial,sans-serif;color:#444;font-weight:normal;text-align:left;border-top:1px solid #ddd;padding-bottom:20px"> </td> </tr>
<tr>
<td style="line-height:1.5;font-size:16px;font-family:Arial,sans-serif;color:#000;padding-bottom:10px;font-weight:bold;text-align:left"> Barang dikirim ke : </td> </tr>
<tr>
<td style="color:#4d485f;font-size:13px;font-family:Arial,sans-serif;padding-bottom:20px;text-align:left;line-height:20px"> <b>Sandy Eko saputra</b> <br>081545699080 <br>Swiss-Belhotel Balikpapan, jl jendral Sudirman kompleks balcony city, KOTA BALIKPAPAN, BALIKPAPAN TIMUR, KALIMANTAN TIMUR, ID, 76113 <br>Balikpapan Timur <br>Kota Balikpapan 76113 </td> </tr>
<tr>
<td style="font-size:11px;line-height:16px;font-family:Arial,sans-serif;color:#444;font-weight:normal;text-align:left;border-top:1px solid #ddd"> </td> </tr>
</tbody></table>
</td> </tr></tbody></table>
</td> </tr></tbody></table>
<table border="0" cellpadding="0" cellspacing="0" width="100%" style="border-collapse:collapse!important"><tbody><tr>
<td bgcolor="#ffffff" align="center" style="font-family:niveau,Arial,sans-serif;line-height:1.5;font-size:14px;color:#4d485f"> <table border="0" cellspacing="0" cellpadding="0" width="100%" align="center" style="border-collapse:collapse!important">
<tbody><tr>
<td style="font-family:niveau,Arial,sans-serif;line-height:1.5;font-size:14px;color:#4d485f;padding:20px 0px 0" align="center"> <a href="https://www.jakmall.com/xiaomi-house/xiaomi-mi-pen-pulpen-premium-original#5189743019035?utm_source=footer-email&amp;utm_medium=email&amp;utm_content=mi-pen&amp;utm_campaign=mi-pen-20170320&amp;jtm_s=footer-email&amp;jtm_m=email&amp;jtm_d=mi-pen&amp;jtm_c=mi-pen-20170320" style="text-decoration:none" target="_blank"><img src="https://ci3.googleusercontent.com/proxy/802Oiok_HzXvnuZxv7UTw2j7owUh38Y2sqLUVZgWYzcBEcViFfoZAlfBLlBSdNbLP25NAjrlvRIQkJsapKFFt4Z_H17mVQ-xkQ=s0-d-e1-ft#https://www.jakmall.com/images/email/ads/mi-pen.jpg" alt="Mi Pen Original" width="600" style="border:0;height:auto;line-height:100%;outline:none;text-decoration:none"></a> </td> </tr>
<tr>
<td style="font-family:niveau,Arial,sans-serif;line-height:1.5;font-size:14px;color:#4d485f;padding:20px 0px" align="center"> <table width="500" border="0" cellspacing="0" cellpadding="0" align="center" class="m_1160478122239317640responsive-table" style="border-collapse:collapse!important">
<tbody><tr>
<td align="center" class="m_1160478122239317640padding-copy" style="font-size:12px;line-height:18px;font-family:&#39;Proxima Nova&#39;,Helvetica,Arial,sans-serif;color:#666666;border-bottom:1px solid #dddddd"> <span class="m_1160478122239317640appleFooter" style="color:#666"> Butuh bantuan? Silakan reply email ini, hubungi (021) 29 508 708, atau kunjungi <a href="http://help.jakmall.com/" class="m_1160478122239317640original-only" style="color:#ff2179;text-decoration:none" target="_blank">halaman bantuan</a> </span><br><br>
</td> </tr>
<tr>
<td align="center" class="m_1160478122239317640padding-copy" style="font-size:12px;line-height:18px;font-family:&#39;Proxima Nova&#39;,Helvetica,Arial,sans-serif;color:#666666;padding-top:20px">  <span class="m_1160478122239317640appleFooter" style="color:#666666"> <a href="https://www.facebook.com/jakmalldotcom" style="color:#999999;text-decoration:none" target="_blank"> <span style="color:#3b5998;font-weight:bold">Facebook</span> </a>   <span style="color:#bbb">•</span>   <a href="https://twitter.com/jakmall" style="color:#999999;text-decoration:none" target="_blank"> <span style="color:#00aced;font-weight:bold">Twitter</span> </a>   <span style="color:#bbb">•</span>   <a href="https://www.instagram.com/jakmall" style="color:#999999;text-decoration:none" target="_blank"> <span style="color:#e4405f;font-weight:bold">Instagram</span> </a>  <span style="color:#bbb">•</span>   <a href="http://line.me/ti/p/%40jakmall" style="color:#999999;text-decoration:none" target="_blank"> <span style="color:#00c300;font-weight:bold">LINE</span> </a>  <span style="color:#bbb">•</span>   <a href="mailto:support@jakmall.com" style="color:#999999;text-decoration:none" target="_blank"> <span style="color:#ff770d;font-weight:bold">Email</span> </a> </span><br><br><br><span class="m_1160478122239317640appleFooter" style="color:#888"> email ini dikirimkan sebagai notifikasi atas interaksi yang dilakukan di website <a 

    href="http://jakmall.com" target="_blank">jakmall.com</a> </span>  </td> </tr>
    </tbody></table>
    </td> </tr>
    </tbody></table>
    </td> </tr></tbody></table>
    </div>

    </div></div><div dir="ltr">-- <br></div><div data-smartmail="gmail_signature"><div dir="ltr">- </div></div>

假设那些数据存储在单元格A1中,如何提取 0110871702023376这个细胞A2和桑迪Eko saputra到细胞A3?

0110871702023376(A2)是一个空运提单号,始终以011XXXXX开头,直到16位数。它通过使用

解决
=REGEXEXTRACT(A1,"011[0-9]\w+")

Sandy Eko saputra怎么样?这是数据包接收者的名称。我坚持要提取这个名字。名称可以是字母数字与下划线,点和斜线相结合。

使用Ctrl + F查找0110871702023376和Sandy Eko saputra

到目前为止,我已成功使用此

获取包含0110871702023376的第一列
=REGEXEXTRACT(A1,"011[0-9]\w+")

1 个答案:

答案 0 :(得分:2)

有几种方法,但从我看到你需要在下一个表格行上得到一个值,正好在一个有Barang dikirim ke文本的地方(Google表示它意味着Goods sent to)。所以,只需匹配此短语,然后匹配行末尾的任何符号,并在末尾添加可选的空格(例如,使用[^>]*</td>\s*</tr>\s*),然后匹配下一行的开头(例如,使用<tr>\s*<td\b[^>]*>\s*和然后匹配粗体标记内的子字符串,捕获除<>之外的任何0+符号:

=REGEXEXTRACT(A1, "Barang dikirim ke[^>]*</td>\s*</tr>\s*<tr>\s*<td\b[^>]*>\s*<b>([^<>]+)</b>")

但是,如果粗体标记内的子字符串始终是唯一的,则可以使用简单的

=REGEXEXTRACT(A1, "<b>([^<>]+)</b>")

请注意,REGEXEXTRACT提取捕获组捕获的字符串部分(在模式中使用一对非转义括号定义)。