How to remove unwanted space in html tags?
-
My html code has some errors
It contains space inside the html tags
Correct ones like
</p>, </div>The current code is like
</ p> or </ div>How to trim/strip all space inside <> by RegEx in Notepad++?
Thanks in advance for sharing your RegEx wisdom.
-
-
@astrosofista said in How to remove unwanted space in html tags?:
(?<=</)\x20+(?=\w+>)
Thanks for the reply.
I tried the code
(?<=</)\x20+(?=\w+>)
It does not seem to be taking an effect
Here is the code
https://regex101.com/r/43a61h/2 -
Hi @NZ-Select
The regex works fine for the provided examples, as I tested on Notepad++.
For the new examples, try this one:
Search: (?-s)< *?(/\w+) *?> Replace: <$1>Take care.
-
@astrosofista said in How to remove unwanted space in html tags?:
(?-s)< *?(/\w+) *?>
Thank you, it indeed works in Notepad++
What if I also want to remove like < / div >, in which the forward slash and div has a space?
Here is the screenshot:

-
Hi @NZ-Select
I was expecting that one :) Easy to solve, indeed, the new regex solves this and the previous ones:
Search: (?-s)< *?(/) *?(\w+) *?> Replace: <$1$2>Take care.
-
@astrosofista said in How to remove unwanted space in html tags?:
<$1$2>
A big thank you, it solved my problem beautifully.
Amazing RegEx code!
Saving me hours of work.
And I hope it is helpful for other people who want to remove the tags as well.Thank you @astrosofista

-
Hi @NZ-Select
You’re welcome. Glad to be of help.
If you want to get involved in regex —is not that hard—, let me suggest you to take a look at this page:
https://npp-user-manual.org/docs/searching/#regular-expressions
Hope this helps.
-
@astrosofista
Thank you for the resource. -
use tiny/xml plugin
-
@WinterSilence said in How to remove unwanted space in html tags?:
use tiny/xml plugin
Can you send me the url of tiny/xml plugin?
I searched this plugin, no result found. -
Search: (?<!>) (?=[/>\w])
Replace:
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login