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"><divid="comment-counter"><span><i></i>14ความคิดเห็น</span><div></div></div></div><divid="comments-jsrender"><div><spanid="comment12-1">ความคิดเห็นที่12-1</span><div><div><ahref="javascript:void(0);"data-06"href="javascript:void(0);"><imgsrc="/images/emotions/icon-emotion-wow.gif"><span>ทึ่ง</span></a><span>0</span></div><divstyle="display:none;"></div></div></div></div></div></div></div><!--barloadmoreส่วนล่าง--><!--default--><!--สำหรับแทรกฟอร์ม--><div></div></div><divid="comments-ed-2"></div><divdata-refzcomment="P0"><span><i></i>แสดงความคิดเห็น</span><div></div></div><scriptlanguage="Javascript"src="/ads.php?position=cafe:skin:supachalasai"></script>
This is the regex command I'm using.
(?<=<span><i><\/i>)(.*)(?=<\/span><div><\/div><\/div>)
I had to use regex to get this.
14ความคิดเห็น
But this is what I got.
14ความคิดเห็น</span><div></div></div></div><divid="comments-jsrender"><div><spanid="comment12-1">ความคิดเห็นที่12-1</span><div><div><ahref="javascript:void(0);"data-06"href="javascript:void(0);"><imgsrc="/images/emotions/icon-emotion-wow.gif"><span>ทึ่ง</span></a><span>0</span></div><divstyle="display:none;"></div></div></div></div></div></div></div><!--barloadmoreส่วนล่าง--><!--default--><!--สำหรับแทรกฟอร์ม--><div></div></div><divid="comments-ed-2"></div><divdata-refzcomment="P0"><span><i></i>แสดงความคิดเห็น
How can I solve the problem?
CodePudding user response:
I Just added a question mark in your regex: (.*) ==> (.*?)
(?<=<span><i><\/i>)(.*?)(?=<\/span><div><\/div><\/div>)
and it worked.
Explanation:
- .*? matches the previous token between zero and unlimited times, as few times as possible, expanding as needed (lazy)