Код: Выделить всё
const text = ":apple: fsdfsd text :apple :apple: banana 2332 :apple: nice :apple:"
console.log("ALL APPLES")
console.log(text.match(/:apple:/g))
console.log("-------------")
/**
*
* @param {string} text
*/
function countApples(text) {
const matches = text.matchAll(/(?(?
< /div>
< /p>
Это выход < /p>
ALL APPLES
[ ':apple:', ':apple:', ':apple:', ':apple:' ]
-------------
Text group: fsd text :apple :apple: banana 2332
[ ':apple:' ]
-------------
Text group: :apple: nice
[ ':apple:' ]
-------------
Text group: :apple:
[ ':apple:' ]
-------------
Подробнее здесь: https://stackoverflow.com/questions/796 ... e-a-js-bug