我有一个网站的源代码,我希望使用正则表达式选择 yearid =" 10287" 。我知道我可以轻松地使用JSoup,但我不想为了这个目的而将库添加到我的项目中。
有关 yearid =" 10287"
的事实yearid 是一个常数,即字母永不改变。
值 10287 会有所不同,可能是84748或746但它总是一个 编号
目前我正在尝试这个:
\s*[yearid]0-9
但它似乎没有起作用。
示例Html
//Skipped the meta and header because I don't need it.
...
<body class="sin" yearid="10287" ezaw='580' ezar='400' style='min-height:200px>
<div class="ks">
<div class="wrap">
<div class="content-right-sidebar-wrap">
<main class="content">
//A lot of unneeded tags
<article class="post-1989009 post type-post post" itemscope="" itemtype="http://schema.org/CreativeWork">
<header class="post-header">
<h1 class="post-title" itemprop="headline">Tyh RGB Marco to habits gtr</h1>
<img src="https://ohniee.com/wp-content/uploads/avatars/1/djsy8933e89ufio8389e8-author-img.jpg" class="avatar user-1-avatar avatar-40 photo" width="40" height="40" alt="Profile photo of Johnnie Adams">
<div class="entry-meta" style="padding-top:3px; margin-left: 50px">
" Written by "<a href="/authors/johnnie"><span class="entry-author" itemprop="author" itemscope="" itemtype="http://schema.org/Person"><span class="entry-author-name" itemprop="name">Johnnie Adams</span></span></a> <script>
document.write(" on April 23rd, 2002 11:28 PM")</script>" on April 23rd, 2002 11:28 PM . "<span class="entry-comments-link"><a href="https://johniee.com/2002/04/thalo-in-American-film-industryk.html#comments">1 Comment</a></span>
</div>
</header>
//A lot of unneeded tags
...
答案 0 :(得分:2)
您的尝试无效,因为[yearid]
部分匹配单个字符,即{y, e, a, r, i, d}
之一;并且0-9
部分与文字序列匹配0-9
(\d
或[0-9]
就是你在那之后的事情。像\byearid=\"[0-9]+\"\b
这样的东西应该有效。
答案 1 :(得分:1)
试试这个正则表达式:/yearid="[0-9]+"/