2016-06-27 1 views
-1

나는이 웹 사이트의 소스 코드를 가지고 있으며, 정규식을 사용하여 yearid = "10287"을 선택하고 싶습니다. 내가 JSoup로 쉽게 할 수 있다는 것을 알고 있지만이 유일한 목적으로 프로젝트에 라이브러리를 추가하고 싶지는 않습니다.정규식에서 yearid = "10287"웹 사이트 소스 코드

현황에 대한 yearid = "10287"

  • yearid는 문자 변경하지 않을 즉 상수이다.

  • 10,287이 다릅니다 값은, 그것은 84748 또는 746이 될 수도 있지만 항상

  • yearid = "10287"이 소스 코드에서 두 번 이상하지만 난 그냥 이 필요를 나타납니다 번호 단일 yearid는 = "10287"는

현재 나는 이것을 시도하고있다 :

\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 

         ... 

답변

1

이 정규식을 시도해보십시오 /yearid="[0-9]+"/

http://regexr.com/3dn2j

+0

감사합니다. 이 문제가 해결되었습니다. – X09

+0

'/ yearid = "[0-9] +"/'를 제외한 모든 문자를 선택하려면 어떻게해야합니까? – X09

2

[yearid] 부분은 {y, e, a, r, i, d}의 하나 인 단일 문자를 일치하기 때문에 작동하지 않습니다 귀하의 시도; 0-9 부분이 리터럴 시퀀스 0-9 (\d 또는 [0-9])을 따라옵니다. \byearid=\"[0-9]+\"\b과 같은 것이 작동합니다.