EmEditor (text editor) Forum Index
   Questions and Answers about EmEditor Core
     check group status
Register To Post

Flat Previous Topic | Next Topic
Poster Thread
Stefan
Posted on: 5/8/2012 10:36 am
Home away from home
Joined: 7/14/2008
From: Germany, EU
Posts: 285
Reg Ex search and replace macro
Quote:

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;


Flat Previous Topic | Next Topic


Subject Poster Date
   check group status user 5/3/2012 7:24 am
     Re: check group status user 5/7/2012 11:55 pm
     Re: check group status Stefan 5/8/2012 1:03 am
       Re: check group status user 5/8/2012 9:47 am
       » Reg Ex search and replace macro Stefan 5/8/2012 10:36 am

Register To Post
 
English čeština Deutsch español français italiano 日本語 한국어 Русский 简体中文 繁體中文