แยกข้อความเฉพาะจากเอกสารโดยใช้แผ่นจดบันทึก ++


0

ฉันมีไฟล์ข้อความที่ฉันต้องการแยกองค์ประกอบข้อมูลที่เฉพาะเจาะจง

ข้อความตัวอย่าง:

<url>
    <loc>https://example.com/example0.html</loc>
    <lastmod>2019-01-22</lastmod>
    <priority>0.5</priority>
</url>
<url>
    <loc>https://example.com/example1.html</loc>
    <lastmod>2019-01-21</lastmod>
    <priority>0.5</priority>
</url>
<url>
    <loc>https://example.com/example2.html</loc>
    <lastmod>2019-01-21</lastmod>
    <priority>0.5</priority>
</url>
<url>
    <loc>https://example.com/example3.html</loc>
    <lastmod>2019-01-20</lastmod>
    <priority>0.5</priority>
</url>
<url>
    <loc>https://example.com/example4.html</loc>
    <lastmod>2019-01-20</lastmod>
    <priority>0.5</priority>
</url>

ฉันต้องการแยก:

https://example.com/example0.html
https://example.com/example1.html
https://example.com/example2.html
https://example.com/example3.html
https://example.com/example4.html

โปรดทราบว่าวันที่ไม่คงที่


คุณหมายถึงอะไร "สกัด"? คุณต้องการลบทุกอย่างยกเว้น URL หรือไม่
Toto

คำตอบ:


0
  • Ctrl + H
  • หาอะไร: <url>\s+<loc>(\S+?)</loc>.+?</url>
  • แทนที่ด้วย: $1
  • ตรวจสอบล้อมรอบ
  • ตรวจสอบการแสดงออกปกติ
  • ตรวจสอบ . matches newline
  • แทนที่ทั้งหมด

คำอธิบาย:

<url>       # literally
  \s+       # 1 or more any spaces, including linebreak
  <loc>     # literally
  (\S+?)    # group 1, 1 or more non spaces, not greedy
  </loc>    # literally
  .+?       # 1 or more any characters, not greedy
</url>      # literally

เปลี่ยน:

$1          # content of group 1, the URL

ตัวอย่างผลลัพธ์ที่ได้รับ:

https://example.com/example0.html
https://example.com/example1.html
https://example.com/example2.html
https://example.com/example3.html
https://example.com/example4.html

1

อาจมีวิธีที่ง่ายกว่าและฉันไม่สามารถเข้าถึง Notepad ++ ได้ในตอนนี้ แต่คุณสามารถลองทำสิ่งต่อไปนี้

ค้นหา: <url>\n\s+<loc>(.*)<\/loc>\n\s.*\n\s.*\n<\/url>

แทนที่: \1

แหล่ง regexr.com/46rin


น่าเศร้าที่มันไม่ทำงานข้อความแสดงข้อผิดพลาด: ไม่พบสิ่งที่เกิดขึ้น
kraus christopher
โดยการใช้ไซต์ของเรา หมายความว่าคุณได้อ่านและทำความเข้าใจนโยบายคุกกี้และนโยบายความเป็นส่วนตัวของเราแล้ว
Licensed under cc by-sa 3.0 with attribution required.