I want to remove every two or more spaces between specific tags and leave just a space instead:
For example:
<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>
My desire output:
<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>
I tried something but it did not work
(?<=<p class="text_obisnuit">)\s*|\s*(?=</p>)
Best Answer
This removes 2 or more spaces only inside
<p class="text_obisnuit">
and</p>
and keep any other multiple spaces.(?:<p class="text_obisnuit">|\G)(?:(?!</p>).)*?\s\K\s+
LEAVE EMPTY
. matches newline
depending if you want to match multiple lines or not.Explanation:
Given text:
Result for given example:
Note: it keeps space just after
<p...>
and just before</p>
If you want to remove these spaces, you have to run another regex:
(?<=<p class="text_obisnuit">)\s+|\s+(?=</p>)
LEAVE EMPTY
Explanation:
Result for given example: