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

Threaded | Oldest First Previous Topic | Next Topic | Bottom
Poster Thread
Stefan
Posted on: 5/8/2012 10:36 am
Home away from home
Joined: 7/14/2008
From: Germany, EU
Posts: 263
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;


user
Posted on: 5/8/2012 9:47 am
Home away from home
Joined: 9/29/2006
From:
Posts: 212
Re: check group status
great thanks!

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

Stefan
Posted on: 5/8/2012 1:03 am
Home away from home
Joined: 7/14/2008
From: Germany, EU
Posts: 263
Re: check group status
Quote:

user wrote:

FROM:
GROUP1{TAB}IT{TAB}EM1{TAB}SENT
GROUP1{TAB}I{TAB}TE M2{TAB}SENT
GROUP2{TAB}IT E M3{TAB}SENT
GROUP2{TAB}ITE{TAB}M4{TAB}NOT SENT
GROUP2{TAB}ITEM5{TAB}SENT

TO:
GROUP1{TAB}SENT
GROUP2{TAB}NOT SENT




Try (with an copy of your file!)
this RegEx search & replace:


FIND: (.+?\t).+\t(NOT SENT|SENT)
REPL: $1$2
[X] Use Regular Expressions



Explanation:
(.+?\t) = match and store all non-greedy till the first TAB into group $1
.+ = match all, but only till:
\t(NOT SENT|SENT) = an TAB followed by "not sent" OR "sent", which ever is stored in $2


.
user
Posted on: 5/7/2012 11:55 pm
Home away from home
Joined: 9/29/2006
From:
Posts: 212
Re: check group status
anyone???
user
Posted on: 5/3/2012 7:24 am
Home away from home
Joined: 9/29/2006
From:
Posts: 212
check group status
hello!

can anyone help me achieve this please (I dont know if regex or macro or anything else is the appropriate way):

I have a text with many lines in this format:

GROUP1{TAB}ITEM1{TAB}SENT
GROUP1{TAB}ITEM2{TAB}SENT
GROUP2{TAB}ITEM3{TAB}SENT
GROUP2{TAB}ITEM4{TAB}NOT SENT
GROUP2{TAB}ITEM5{TAB}SENT

GROUP1, GROUP2, etc are multidigit numbers

ITEM1, ITEM2, etc are any kind of characters sequence, including TABs, spaces, etc

the logic is that if in a GROUP, there is a single or more ITEM that is NOT SENT, then the whole GROUP must be marked as NOT SENT

if all items of a GROUP are SENT, then the GROUP is marked as SENT

so I want, with a click, to transform the above text into:

GROUP1{TAB}SENT
GROUP2{TAB}NOT SENT

any solution?

thanks!
Threaded | Oldest First Previous Topic | Next Topic | Top


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