1

I want to filter anything between 2 tags but It skipped the first tag, I don't know what to do.

this is my raw string :

<!--ENTEXPERTCOMMENT--><divid="comments-counts"><divclass="display-post-wrapperpageno-titlepageno-title-counter"id="comment-counter"><spanclass="title"><iclass="icon-header-badge3chat"></i>14ความคิดเห็น</span><divclass="pageno-title-line"></div></div></div><divid="comments-jsrender"><divclass="display-post-status-leftside"><spanclass="display-post-number"id="comment12-1">ความคิดเห็นที่12-1</span><divclass="display-post-edit"><divclass="display-post-edit-wrapper"><ahref="javascript:void(0);"data-06"href="javascript:void(0);"><imgclass=""src="/images/emotions/icon-emotion-wow.gif"><spanclass="label">ทึ่ง</span></a><spanclass="emotion-choice-score">0</span></div><divclass="emotion-vote-usersmall-txt-fixed"style="display:none;"></div></div></div></div></div></div></div><!--barloadmoreส่วนล่าง--><!--default--><!--สำหรับแทรกฟอร์ม--><divclass="comment-80761053form"></div></div><divclass="l-end"id="comments-ed-2"></div><divclass="display-post-wrapperpageno-titlepageno-title-counter"data-refzcomment="P0"><spanclass="title"><iclass="icon-header-badge3comment"></i>แสดงความคิดเห็น</span><divclass="pageno-title-line"></div></div><scriptlanguage="Javascript"src="/ads.php?position=cafe:skin:supachalasai"></script>

This is the regex command I'm using.

(?<=<spanclass="title"><iclass="icon-header-badge3chat"><\/i>)(.*)(?=<\/span><divclass="pageno-title-line"><\/div><\/div>)

I had to use regex to get this.

14ความคิดเห็น

But this is what I got.

14ความคิดเห็น</span><divclass="pageno-title-line"></div></div></div><divid="comments-jsrender"><divclass="display-post-status-leftside"><spanclass="display-post-number"id="comment12-1">ความคิดเห็นที่12-1</span><divclass="display-post-edit"><divclass="display-post-edit-wrapper"><ahref="javascript:void(0);"data-06"href="javascript:void(0);"><imgclass=""src="/images/emotions/icon-emotion-wow.gif"><spanclass="label">ทึ่ง</span></a><spanclass="emotion-choice-score">0</span></div><divclass="emotion-vote-usersmall-txt-fixed"style="display:none;"></div></div></div></div></div></div></div><!--barloadmoreส่วนล่าง--><!--default--><!--สำหรับแทรกฟอร์ม--><divclass="comment-80761053form"></div></div><divclass="l-end"id="comments-ed-2"></div><divclass="display-post-wrapperpageno-titlepageno-title-counter"data-refzcomment="P0"><spanclass="title"><iclass="icon-header-badge3comment"></i>แสดงความคิดเห็น

How can I solve the problem?

1 Answers1

0

I Just added a question mark in your regex: (.*) ==> (.*?)

(?<=<spanclass="title"><iclass="icon-header-badge3chat"><\/i>)(.*?)(?=<\/span><divclass="pageno-title-line"><\/div><\/div>)

and it worked.

Demo

Explanation:

  • .*? matches the previous token between zero and unlimited times, as few times as possible, expanding as needed (lazy)
Mustofa Rizwan
  • 10,215
  • 2
  • 28
  • 43