Skip to content

Instantly share code, notes, and snippets.

@OrderAndCh4oS
Created September 25, 2024 23:56
Show Gist options
  • Select an option

  • Save OrderAndCh4oS/099b346e1f753c5a4a9bb6cdb2d71e5b to your computer and use it in GitHub Desktop.

Select an option

Save OrderAndCh4oS/099b346e1f753c5a4a9bb6cdb2d71e5b to your computer and use it in GitHub Desktop.
Word Boundaries
const text = `Þig, sem í fjarlægð fjöllin bak við dvelur
og fagrar vonir tengdir líf mitt við,
minn hugur þráir, hjartað ákaft saknar,
er horfnum—stundum ljúfum dvel ég hjá.
Heyrirðu ei hvern hjartað kallar á?
Heyrirðu ei storm er kveðju mína ber?
Þú fagra minning eftir skildir eina,
sem aldrei gleymist, meðan lífs ég er.`
const enDashEmDashOrForwardSlash = /[\u2013\u2014/]/g;
const anyCombinationOfCharactersNumbersOrPunctuationMarks = /[\p{L}\p{N}][\p{L}\S]*/gu
console.log(text
.normalize("NFKC")
.replace(enDashEmDashOrForwardSlash, " ")
.match(anyCombinationOfCharactersNumbersOrPunctuationMarks)?.length ?? 0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment