Q. Want to display only string which has same character
var x=["aa","ab","ac","ba","bb","bc","ca","cb","cc"];
//desired output- aa,bb,cc
//i am trying
console.log(x.filter(y=>(/(?=\w+)(?=\w{2})/).test(y)));
Please help me to get solve
Q. Want to display only string which has same character
var x=["aa","ab","ac","ba","bb","bc","ca","cb","cc"];
//desired output- aa,bb,cc
//i am trying
console.log(x.filter(y=>(/(?=\w+)(?=\w{2})/).test(y)));
Please help me to get solve
I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make easier to read.
See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>
) will also add backticks around text.
Note: Backticks are not single quotes.
Hint: look at backreferencing captured groups.
Thank You @ArielLeslie.
It solves my problem
console.log(x.filter(y=>(/(\w)\1/).test(y)))
I’m glad I could help. Happy coding!