EmEditor (text editor) Forum Index
   Regular Expressions
     find the max number
Register To Post

Threaded | Oldest First Previous Topic | Next Topic | Bottom
Poster Thread
Stefan
Posted on: 11/5/2011 10:14 am
Home away from home
Joined: 7/14/2008
From: Germany, EU
Posts: 261
Re: find the max number
No, an RegEx is an pattern matching system only.
There are very little comparing features.

You will need to use an macro/script for that.
How that macro will work and what you will get as
result depends on your real current needs and how
the rest of the line looks a like: are that digits
and tabs the only signs in such an line?

Here is an quick example code.
Be sure to use this always with copies of your importent documents.
Because i don't have an impression what could get worse.
If anyone should improve this script for you we will need an
better example how the rest of such an line will look a like.

Ahh, and this script will work only with tabs as delimiter
or it have to be adjusted as one needs.




////===== Description: ==================
//// Click into an line and execute this macro/script.
//// The line will split at tab stops 
//// and if an part is detected as an number
//// the greatest number is stored as vBiggestNumber for your use.


//// ====== Setting: ====================
//// Split line at tab. Use your own delimiter if needed:
SplitAt = "\t";


//// ====== Work: ======================
//// Get current line content:
document.selection.SelectLine();
CurrLine = document.selection.text;
//// Call function to split str and find biggest number:
vBiggestNumber = ReturnLargedNumber(CurrLine, SplitAt);


//// ====== End: =======================
//// Do something with the result:
alert('result: >' + vBiggestNumber + '<');
//document.selection.Collapse();
//document.selection.NewLine( );
document.selection.text = vBiggestNumber;


////======================================
////======== Function =====================
function ReturnLargedNumber(str,delim)
 {
    Tokens = str.split(delim);
    vMaxNumber = 0;
    for (x = 0; x < Tokens.length; x++) 
    { 
       vCurrentNumb = Tokens[x]; 
       if (!isNaN(vCurrentNumb))
       {
          if (Number(vCurrentNumb) > vMaxNumber)
          {
            vMaxNumber = vCurrentNumb;
          } 
       }
    }
 return vMaxNumber;
 }





HTH?

 
user
Posted on: 11/5/2011 5:25 am
Home away from home
Joined: 9/29/2006
From:
Posts: 212
find the max number
hello

is there a regular expression that will replace a string of numbers seperated by TAB, with the maximum numbers of this number set?

for example:
[TAB]3[TAB]2[TAB]5[TAB]1[TAB]
replaced with:
5

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


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