April 10, 2013 at 6:43 pm #10937
Stefan
Participant
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 = /dddd/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("rn");
}else{
return "No match found.";
}
}
_