-1

I'm trying to create a Giveaway Picker for Instagram. The Rules for the Giveaway are: tag 3 Friends in the comments.

A regular comment should now be @pers1 @pers2 @pers3. How can I check if there are at least 3 @ symbols in the comment.

I alredy loaded all comments into the variable comments.

I think it would work with Regex. But I'm not so good in regex. Does anyone have a working regex for this? THX.

Kinay
  • 37
  • 2
  • 7

1 Answers1

0

If you want to use a regular expression, you can use a global match and test the length of the result:

const numberOfAts = str => str.match(/@/g).length;
console.log(numberOfAts('@pers1 @pers2 @pers3'));
console.log(numberOfAts('@pers1 @pers2 @pers3 @pers4'));
console.log(numberOfAts('@pers1 @pers2'));
CertainPerformance
  • 356,069
  • 52
  • 309
  • 320