สิ่งนี้จะลบพื้นที่ 2 หรือมากกว่าเท่านั้น ภายใน <p class="text_obisnuit">
และ </p>
และเก็บช่องว่างอื่น ๆ อีกหลายช่อง
- Ctrl + H
- หาอะไร:
(?:<p class="text_obisnuit">|\G)(?:(?!</p>).)*?\s\K\s+
- แทนที่ด้วย:
LEAVE EMPTY
- ตรวจสอบล้อมรอบ
- ตรวจสอบการแสดงออกปกติ
- อย่าตรวจสอบ
. matches newline
ขึ้นอยู่กับว่าคุณต้องการจับคู่หลายบรรทัดหรือไม่
- แทนที่ทั้งหมด
คำอธิบาย:
(?: # start non capture group
<p class="text_obisnuit"> # literally
| # OR
\G # restart from position of last match
) # end group
(?: # start non capture group
(?!</p>) # negative lookahead, make sure we haven't reach </p>
. # any character
)*? # group may appear 0 or more times, not greedy
\s # a space
\K # forget all we have seen until this position
\s+ # 1 or more spaces
รับข้อความ:
other text
<p class="text_obisnuit"> The context of articles, stories, and conversations helps you figure out and understand the meaning of English words in the text that are new to you. </p>
other text
ตัวอย่างผลลัพธ์ที่ได้รับ:
other text
<p class="text_obisnuit"> The context of articles, stories, and conversations helps you figure out and understand the meaning of English words in the text that are new to you. </p>
other text
บันทึก: มันช่วยให้พื้นที่หลังจาก <p...>
และก่อนหน้านี้ </p>
หากคุณต้องการลบช่องว่างเหล่านี้คุณต้องเรียกใช้ regex อื่น:
- Ctrl + H
- หาอะไร:
(?<=<p class="text_obisnuit">)\s+|\s+(?=</p>)
- แทนที่ด้วย:
LEAVE EMPTY
- ยกเลิกการเลือกกรณีการจับคู่
- ตรวจสอบล้อมรอบ
- ตรวจสอบการแสดงออกปกติ
- แทนที่ทั้งหมด
คำอธิบาย:
(?<= # start positive lookbehind, make sure we have
<p class="text_obisnuit"> # literally
) # end lookbehind
\s+ # 1 or more spaces
| # OR
\s+ # 1 or more spaces
(?= # start positive lookahead
</p> # literally
) # end lookahead
ตัวอย่างผลลัพธ์ที่ได้รับ:
other text
<p class="text_obisnuit">The context of articles, stories, and conversations helps you figure out and understand the meaning of English words in the text that are new to you.</p>
other text