i work in javascript and like to check if my text has some signs. I’d like to check if my text has ( ) and & letters or it has repeating letters in it. Some examples:
test – has multiple t
tes&t – has &
test(test) – has ( and ), multiple t and twice ‘e’ letter
test&(test – has & and ( and multiple t and e
test&(&t – has multiple t, multiple & and (
tesra – this one doesnt fits any patterns
I’ve already made something like this:
if ((/(\w+)(?=\1)/g).test(str)) alert('multiple signs')
but it only counts multiple signs if they are one after another so ‘teest’ would fit pattern and test wouldnt. Can anybody help me? I never could understand all those regexp features 🙁
It can be divided in two regexp.
Thanx in advance
This should do it, though it might not be very efficient (since it is not anchored):
An alternative would be to simply iterate over the characters, inspect and count them:
(I admit the function name does not fit very well)