I specialize in working with JavaScript and I have a need to verify if my text contains certain characters. Specifically, I want to check for the presence of parentheses (), ampersands (&), and repeating letters within the text. Here are some examples:
test - contains multiple instances of 't'
tes&t - contains '&'
test(test) - contains '(' and ')', multiple 't's, and two occurrences of 'e'
test&(test - contains '&', '(', multiple 't's, and 'e's
test&(&t - contains multiple 't's, multiple '&'s, and '('
tesra - does not match any patterns mentioned above
I've already written the following code snippet:
if ((/(\w+)(?=\1)/g).test(str)) alert('multiple signs')
However, this code only detects consecutive duplicate signs, so 'teest' would be detected but 'test' wouldn't. Can anyone provide assistance with this? RegEx features have always been challenging for me :( This task can probably be tackled using two separate RegEx expressions.
Thank you in advance