EmEditor (text editor) Forum Index
   Regular Expressions
     count and select all the regex matches
Register To Post

Threaded | Newest First Previous Topic | Next Topic | Bottom
Poster Thread
user
Posted on: 9/19/2012 4:12 am
Home away from home
Joined: 9/29/2006
From:
Posts: 212
count and select all the regex matches
hello!

how can I return the number of found regex matches?

how can I select the regex matches?

thanks!
Yutaka
Posted on: 9/20/2012 4:03 pm
Webmaster
Joined: 9/28/2006
From: Redmond
Posts: 2399
Re: count and select all the regex matches
Hello,

Is this about macros?

Thanks!


----------------
Yutaka Emura
Developer of EmEditor
http://www.emeditor.com/

user
Posted on: 4/10/2013 2:23 am
Home away from home
Joined: 9/29/2006
From:
Posts: 212
Re: count and select all the regex matches
I am not sure

I just want to have these options when I do a regex search

is it possible?

thanks!!!
Stefan
Posted on: 4/10/2013 6:09 am
Home away from home
Joined: 7/14/2008
From: Germany, EU
Posts: 263
Re: count and select all the regex matches
Quote:

user wrote:
count all the regex matches
I just want to have these options when I do a regex search


You can check "[X] Count Matches" and click at [Find Next]
to see the count in the status bar.


Quote:

user wrote:
select all the regex matches
I just want to have these options when I do a regex search


You can click at [Bookmark All]
and then utilize "Edit > Bookmarks"

Or use a script/macro to collect all matches.
In the Library you can find e.g. "Macro to extract strings using regular expression"
Stefan
Posted on: 4/10/2013 10:43 am
Home away from home
Joined: 7/14/2008
From: Germany, EU
Posts: 263
Re: count and select all the regex matches
Quote:

user wrote:
hello!

how can I return the number of found regex matches?

how can I select the regex matches?

thanks!


One could utilize a macro like this basic example:
//Text to parse for RegEx:
selText = document.selection.text;

//Show matches:
vResults = findMatches(selText);
alert(vResults);


function findMatches(inputStr){
	//Build an expression to match what you want:
    //var regex = /\d\d\d\d/ig; // match 2013
    var regex = /www\..+?\..{2,3}/ig; //match www.emeditor.com
    
    //To avoid errors, check beforehand if test is successful:
	if(regex.test(inputStr)){
		//if test was ok, collect matches:
	    result= inputStr.match(regex);
	    //some cosmetic:
    	count = result.length; 
    	status = "Macro found " + count + " matches.";
    	//return result to caller:
    	return result.join("\r\n");
    }else{
    	return "No match found.";
    }
}



_
user
Posted on: 4/10/2013 11:00 am
Home away from home
Joined: 9/29/2006
From:
Posts: 212
Re: count and select all the regex matches
it's great, many thanks!
Threaded | Newest First Previous Topic | Next Topic | Top


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