简体   繁体   中英

How to extract data from Google spreadsheet by using REGEXEXTRACT regex

Here is the code retrieved from e-mail. This contains two main informations that should be extracted to other cell in a Google spreadsheet.

<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>

Suppose that those data is stored in cell A1, how to extract 0110871702023376 this to cell A2 and Sandy Eko saputra to cell A3?

0110871702023376 (A2) is an airway bill number, this always starts with 011XXXXX until 16 digits. It solved by using

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

How about the Sandy Eko saputra? This is a name of the receiver of the packet. I am stuck to extract this name. The name could be alphanumeric combined with underscore, point and slash.

Using Ctrl + F to find 0110871702023376 and Sandy Eko saputra

Until now, I have succeed to get the first column which contains 0110871702023376 by using this

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

There are several ways, but from what I see you need to get a value on the next table row, right below one having Barang dikirim ke text (Google says it means Goods sent to ). So, just match this phrase and then any symbols up to the row end with optional whitespace at the end (say, with [^>]*</td>\\s*</tr>\\s* ), then match the start of the next row (say, with <tr>\\s*<td\\b[^>]*>\\s* and then match the substring inside bold tags capturing any 0+ symbols other than < and > in-between:

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

However, if the substring inside bold tags is always unique, you may just use a simple

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

Note that REGEXEXTRACT extracts the the part of string captured with a capturing group (defined with a pair of unescaped parentheses inside the pattern).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM