Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #10310
    user
    Participant

    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!

    #10335
    user
    Participant

    anyone???

    #10336
    Stefan
    Participant

    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

    .

    #10339
    user
    Participant

    great thanks!

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

    #10340
    Stefan
    Participant

    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;


Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.