Last active
April 19, 2021 08:15
-
-
Save yuval-a/ad8dd131506c56da2a634693db72e2c9 to your computer and use it in GitHub Desktop.
str_length that ignores Hebrew "nikud" characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode 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; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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