How to count the number of matches in the text?
For example, text:
“The British monopolized Bengal's foreign trade, as well as the most important branches of Bengal's internal trade. Hundreds of thousands of Bengali artisans were forcibly attached to the company's trading posts, where they had to deliver their products at minimal prices. Taxes have skyrocketed. '
text.match (RegExp (str, 'g')) ?. length ?? 0
text.split (str) .length - 1Anonymous
To place the code, please use CodePen or similar tool. Thanks you!