Skip to content

Instantly share code, notes, and snippets.

@yuval-a
Last active April 19, 2021 08:15
Show Gist options
  • Save yuval-a/ad8dd131506c56da2a634693db72e2c9 to your computer and use it in GitHub Desktop.
Save yuval-a/ad8dd131506c56da2a634693db72e2c9 to your computer and use it in GitHub Desktop.
str_length that ignores Hebrew "nikud" characters
function str_length(str) {
let length = 0, nikud_chars = /[ְֱֲֳִֵֶַָֹֻּׁׂ]/;
for (let i=0,len=str.length;i<len;i++)
length += nikud_chars.test(str[i]) ? 0 : 1;
return length;
}
// A better, faster approach, as devised by the Israeli Javascript Facebook group :)
function str_length(str) {
return str.replace(/[\u0590-\u05c7]/g,'').length;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment