javascript - Counting specific characters in a textarea -
other questions have been asked concerning word count in text areas, not duplicates of question:
what trying write javascript/jquery function called on user clicking on button. function takes value of textarea , checks characters in there. , check whether 2 characters have same amount of occurrences. in function need utilize if-else statement.
example: if input has 3x [ , 3x ]: if (a.length == b.length) {} (= true)
if input has 3x [ , 2x ]: if (a.length == b.length) {} (= false)
but not quite sure how can count individual characters. guessing regex , match, next not seem work:
var = str.match(/\[+ /g), b = str.match(/\[+ /g); if (a.length == b.length) {//do something}
here fiddle. can see, count not correct.
how about:
'a[b][ca[]de'.match(/\[/g).length; output:
3 as expected.
javascript jquery regex match
No comments:
Post a Comment