Skip to content

Instantly share code, notes, and snippets.

@ruzz311
Last active January 10, 2025 10:25
Show Gist options
  • Save ruzz311/073ae57c471a97b6cefa1a39db5d3a69 to your computer and use it in GitHub Desktop.
Save ruzz311/073ae57c471a97b6cefa1a39db5d3a69 to your computer and use it in GitHub Desktop.
Regex example to remove spaces between tags (html, xml, etc.)
// For regex testing https://regex101.com/r/dOjkeJ/2
let myStr = `<something>
<xml-like>
<example><p>with lots of spaces</p></example>
and \n characters
<xml-like>
</something>`;
// spaces:
myStr.replace(new RegExp('\>[ ]+\<', 'g'), '><');
// matches "\n" "\t" and " " (space)
myStr.replace(new RegExp('\>[\s]+\<', 'g'), '><');
@ruzz311
Copy link
Author

ruzz311 commented Jan 10, 2025

Bro, I don't even remember writing this. It's some snippet from 2017

@SparK-Cruz
Copy link

Well, almost 8 years later and it put me on track to make something work so, thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment