html - 如何使用来自 HTML 的##(th 或 nd 或 st)从 html 格式中提取特定事件的正则表达式日期
问题描述
从下面的 html 块中,我试图提取作为24th May, 6:00 - 9:00pm
事件日期的日期Sally Molloy: Backyard Worlds
。
</script>
<div class="entry"></div>
<div class="post-listing ">
<article class="item-list item_1">
<h2 class="post-title"><a href="http://bneart.com/sally-molloy-backyard-worlds/" title="Permalink to Sally Molloy: Backyard Worlds" rel="bookmark">Sally Molloy: Backyard Worlds</a></h2>
<p class="post-meta">
</p>
<div class="post-thumbnail">
<a href="http://bneart.com/sally-molloy-backyard-worlds/" title="Permalink to Sally Molloy: Backyard Worlds" rel="bookmark">
<img width="150" height="150" src="./Art_files/60258048_430912857673313_3106041492867645440_o-1024x818.jpg" class="attachment-tie-large size-tie-large wp-post-image" alt=""> </a>
</div><!-- post-thumbnail /-->
<div class="entry">
<div class="whatson">
<h5><span class="caps">WHEN</span> : 24th May, 6:00 - 9:00pm</h5>
<h5><span class="caps">WHERE</span> : <a href="https://www.facebook.com/events/387735931952215/" class="external" target="_blank"> Innerspace Contemporary Art</a></h5>
</div>
<p>please join us for the opening celebration of backyard worlds, an exhibition of new paintings by sally molloy. backyard worlds is ...</p>
<a class="more-link" href="http://bneart.com/sally-molloy-backyard-worlds/">Read More »</a>
</div>
<div class="clear"></div>
</article><!-- .item-list -->
<article class="item-list item_2">
<h2 class="post-title"><a href="http://bneart.com/confronting-contemporary-art-international-museum-day/" title="Permalink to Confronting Contemporary Art: International Museum Day" rel="bookmark">Confronting Contemporary Art: International Museum Day</a></h2>
<p class="post-meta">
</p>
<div class="post-thumbnail">
<a href="http://bneart.com/confronting-contemporary-art-international-museum-day/" title="Permalink to Confronting Contemporary Art: International Museum Day" rel="bookmark">
<img width="150" height="150" src="./Art_files/59806737_10156092429451716_1848756487740981248_o-1024x683.jpg" class="attachment-tie-large size-tie-large wp-post-image" alt=""> </a>
</div><!-- post-thumbnail /-->
<div class="entry">
<div class="whatson">
<h5><span class="caps">WHEN</span> : 18th May, 10:30 - 11:30am</h5>
<h5><span class="caps">WHERE</span> : <a href="https://www.facebook.com/events/636159330185990/" class="external" target="_blank">QAGOMA</a></h5>
</div>
<p>We’re confronting Contemporary Art on International Museum Day, join us! The Australian Collection at QAG brings the Indigenous and contemporary Australian ...</p>
<a class="more-link" href="http://bneart.com/confronting-contemporary-art-international-museum-day/">Read More »</a>
</div>
<div class="clear"></div>
</article><!-- .item-list -->
<article class="item-list item_3">
<h2 class="post-title"><a href="http://bneart.com/the-great-masculine-renunciation/" title="Permalink to The Great Masculine Renunciation" rel="bookmark">The Great Masculine Renunciation</a></h2>
<p class="post-meta">
</p>
<div class="post-thumbnail">
<a href="http://bneart.com/the-great-masculine-renunciation/" title="Permalink to The Great Masculine Renunciation" rel="bookmark">
<img width="150" height="150" src="./Art_files/58551664_10157122584896399_5017378944056295424_n-1.jpg" class="attachment-tie-large size-tie-large wp-post-image" alt=""> </a>
</div><!-- post-thumbnail /-->
<div class="entry">
<div class="whatson">
<h5><span class="caps">WHEN</span> : 25th May, 6:00 - 9:00pm</h5>
<h5><span class="caps">WHERE</span> : <a href="https://www.facebook.com/events/391914351653072/" class="external" target="_blank">Outer Space</a></h5>
</div>
<p>Sal J Edwards’ ‘The Great Masculine Renunciation’ presents a menswear collection that responds to the contemporary call for the redefining and ...</p>
<a class="more-link" href="http://bneart.com/the-great-masculine-renunciation/">Read More »</a>
</div>
<div class="clear"></div>
</article><!-- .item-list -->
<article class="item-list item_4">
<h2 class="post-title"><a href="http://bneart.com/mirror-mine-caitlin-franzmann-ben-russell/" title="Permalink to Mirror Mine: Caitlin Franzmann / Ben Russell" rel="bookmark">Mirror Mine: Caitlin Franzmann / Ben Russell</a></h2>
<p class="post-meta">
</p>
<div class="post-thumbnail">
<a href="http://bneart.com/mirror-mine-caitlin-franzmann-ben-russell/" title="Permalink to Mirror Mine: Caitlin Franzmann / Ben Russell" rel="bookmark">
<img width="150" height="150" src="./Art_files/59447604_2188861394528839_6705394841930432512_n.jpg" class="attachment-tie-large size-tie-large wp-post-image" alt=""> </a>
</div><!-- post-thumbnail /-->
<div class="entry">
<div class="whatson">
<h5><span class="caps">WHEN</span> : 11th - 24th May</h5>
<h5><span class="caps">WHERE</span> : <a href="https://www.facebook.com/events/376696563193218/" class="external" target="_blank">Outer Space</a></h5>
</div>
<p>Presented in partnership between Queensland Film Festival and Outer Space ARI, ‘Mirror Mine’ examines mining through the work of Brisbane artist ...</p>
<a class="more-link" href="http://bneart.com/mirror-mine-caitlin-franzmann-ben-russell/">Read More »</a>
</div>
<div class="clear"></div>
我正在尝试将正则表达式与 (?<=...).*?(?=...) 和日期的结构结合使用,但我对正则表达式不太熟悉。有什么线索吗?
解决方案
以下函数将搜索给定的标签节点列表,并将给定字符串的任何匹配项作为数组返回。
const date = `24th May, 6:00 - 9:00pm`;
const findString = (selector, string) => {
const nodes = document.querySelectorAll(selector);
//console.log(nodes);
let output = [];
for (let [index, node] of nodes.entries()) {
if (node.textContent.includes(string)) {
output.push(`${string} at ${selector}${index}`);
}
}
return output;
}
console.log(findString('h5', date));
<div class="entry"></div>
<div class="post-listing ">
<article class="item-list item_1">
<h2 class="post-title"><a href="http://bneart.com/sally-molloy-backyard-worlds/" title="Permalink to Sally Molloy: Backyard Worlds" rel="bookmark">Sally Molloy: Backyard Worlds</a></h2>
<p class="post-meta"></p>
<div class="post-thumbnail">
<a href="http://bneart.com/sally-molloy-backyard-worlds/" title="Permalink to Sally Molloy: Backyard Worlds" rel="bookmark">
<img width="150" height="150" src="./Art_files/60258048_430912857673313_3106041492867645440_o-1024x818.jpg" class="attachment-tie-large size-tie-large wp-post-image" alt=""> </a>
</div>
<!-- post-thumbnail /-->
<div class="entry">
<div class="whatson">
<h5><span class="caps">WHEN</span> : 24th May, 6:00 - 9:00pm</h5>
<h5><span class="caps">WHERE</span> : <a href="https://www.facebook.com/events/387735931952215/" class="external" target="_blank"> Innerspace Contemporary Art</a></h5>
</div>
<p>please join us for the opening celebration of backyard worlds, an exhibition of new paintings by sally molloy. backyard worlds is ...</p>
<a class="more-link" href="http://bneart.com/sally-molloy-backyard-worlds/">Read More »</a>
</div>
<div class="clear"></div>
</article>
<!-- .item-list -->
<article class="item-list item_2">
<h2 class="post-title"><a href="http://bneart.com/confronting-contemporary-art-international-museum-day/" title="Permalink to Confronting Contemporary Art: International Museum Day" rel="bookmark">Confronting Contemporary Art: International Museum Day</a></h2>
<p class="post-meta"></p>
<div class="post-thumbnail">
<a href="http://bneart.com/confronting-contemporary-art-international-museum-day/" title="Permalink to Confronting Contemporary Art: International Museum Day" rel="bookmark">
<img width="150" height="150" src="./Art_files/59806737_10156092429451716_1848756487740981248_o-1024x683.jpg" class="attachment-tie-large size-tie-large wp-post-image" alt=""> </a>
</div>
<!-- post-thumbnail /-->
<div class="entry">
<div class="whatson">
<h5><span class="caps">WHEN</span> : 18th May, 10:30 - 11:30am</h5>
<h5><span class="caps">WHERE</span> : <a href="https://www.facebook.com/events/636159330185990/" class="external" target="_blank">QAGOMA</a></h5>
</div>
<p>We’re confronting Contemporary Art on International Museum Day, join us! The Australian Collection at QAG brings the Indigenous and contemporary Australian ...</p>
<a class="more-link" href="http://bneart.com/confronting-contemporary-art-international-museum-day/">Read More »</a>
</div>
<div class="clear"></div>
</article>
<!-- .item-list -->
<article class="item-list item_3">
<h2 class="post-title"><a href="http://bneart.com/the-great-masculine-renunciation/" title="Permalink to The Great Masculine Renunciation" rel="bookmark">The Great Masculine Renunciation</a></h2>
<p class="post-meta"></p>
<div class="post-thumbnail">
<a href="http://bneart.com/the-great-masculine-renunciation/" title="Permalink to The Great Masculine Renunciation" rel="bookmark">
<img width="150" height="150" src="./Art_files/58551664_10157122584896399_5017378944056295424_n-1.jpg" class="attachment-tie-large size-tie-large wp-post-image" alt=""> </a>
</div>
<!-- post-thumbnail /-->
<div class="entry">
<div class="whatson">
<h5><span class="caps">WHEN</span> : 25th May, 6:00 - 9:00pm</h5>
<h5><span class="caps">WHERE</span> : <a href="https://www.facebook.com/events/391914351653072/" class="external" target="_blank">Outer Space</a></h5>
</div>
<p>Sal J Edwards’ ‘The Great Masculine Renunciation’ presents a menswear collection that responds to the contemporary call for the redefining and ...</p>
<a class="more-link" href="http://bneart.com/the-great-masculine-renunciation/">Read More »</a>
</div>
<div class="clear"></div>
</article>
<!-- .item-list -->
<article class="item-list item_4">
<h2 class="post-title"><a href="http://bneart.com/mirror-mine-caitlin-franzmann-ben-russell/" title="Permalink to Mirror Mine: Caitlin Franzmann / Ben Russell" rel="bookmark">Mirror Mine: Caitlin Franzmann / Ben Russell</a></h2>
<p class="post-meta"></p>
<div class="post-thumbnail">
<a href="http://bneart.com/mirror-mine-caitlin-franzmann-ben-russell/" title="Permalink to Mirror Mine: Caitlin Franzmann / Ben Russell" rel="bookmark">
<img width="150" height="150" src="./Art_files/59447604_2188861394528839_6705394841930432512_n.jpg" class="attachment-tie-large size-tie-large wp-post-image" alt=""> </a>
</div>
<!-- post-thumbnail /-->
<div class="entry">
<div class="whatson">
<h5><span class="caps">WHEN</span> : 11th - 24th May</h5>
<h5><span class="caps">WHERE</span> : <a href="https://www.facebook.com/events/376696563193218/" class="external" target="_blank">Outer Space</a></h5>
</div>
<p>Presented in partnership between Queensland Film Festival and Outer Space ARI, ‘Mirror Mine’ examines mining through the work of Brisbane artist ...</p>
<a class="more-link" href="http://bneart.com/mirror-mine-caitlin-franzmann-ben-russell/">Read More »</a>
</div>
<div class="clear"></div>
推荐阅读
- python - 如何在 Huggingface + CUDA 内存不足的 BERT 之上添加 BiLSTM。尝试分配 16.00 MiB
- java - 用斜杠替换文字的 Java 把手
- python - Django 模型如何修复循环导入错误?
- c - C 指向数据。为什么显示错误;二进制的无效操作数?
- c - 将 char* 复制到 char* 的指针
- android - Android错误膨胀类
加载高图时 - css - 如何在溢出设置为可见时显示线性渐变的边框半径 - React Native IOS
- python - 需要很好地解释这个小 Python 代码
- postgresql - 使用 JPA Criteria 复制 PostgreSQL select distinct on + multiple order by 条件
- sockets - Dart客户端Socket连接但不向服务器发送数据?