#10340
Stefan
Participant

user wrote:
great thanks!

how do I count the instances of a match and store the amount in a variable?

Do the RegEx s&r with an macro.

For example i have found that this
JavaScript macro could be an base for your issue:



//select your text, then execute the macro
if (document.selection.IsEmpty){alert('Nothing selected?'); quit();}
SelText = document.selection.text;
alert(SelText); // <== only for testing


//Settings:
MatchREx = "(.+?t).+t(NOT SENT|SENT)"; //Match/Find this
ReplWith = "$1$2"; //Replace with that
REModify = "gi"; //(G)lobal, (i)gnor case, (M)ultiline


//How many matches?
Matches = SelText.match(RegExp(MatchREx,REModify)).length;

//Do the RegEx search&replace itself:
ReplacedStr = SelText.replace(RegExp(MatchREx,REModify),ReplWith);


//The output:
alert(Matches + ' matches found'); // <== only for testing
alert(ReplacedStr); // <== only for testing

//Overwrite the selected text:
//document.selection.text = ReplacedStr;