Ozuf Ozuf - 1 year ago 53
Java Question

Regex to yearid="10287" from a website source code

I have this source code of a website and I want select yearid="10287" from it using regex. I know I can easily do it with JSoup but I just don't want to add the library to my project for this sole purpose.

Facts about yearid="10287"

  • yearid is a constant ie the letters never change.

  • The value 10287 varies, it might be 84748 or 746 but it is always a

  • yearid="10287" appears more than once in the source code but I just
    need a single yearid="10287"

Currently I am trying this:


but it seems not to be working.

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

//A lot of unneeded tags


Answer Source

Try this regex: /yearid="[0-9]+"/


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download