Batch Find/Replace, and/or exporting macros

  • MyOhMyke

    MyOhMyke - 2013-03-12

    I made a macro that batches find/replacements to turn:

    [SLOT_HEAD] = "Helm",
    [SLOT_BODY] = "Armor",
    [SLOT_HANDS] = "Gloves",

    and want to try to share it with others who will find it useful. There's up to 16 slots that need to be replaced like that, plus the formatting around each set as well. Is there a plug-in or other option that will do this for me without needing to record a macro? It might be more user-friendly for less computer-savvy people to understand.

    I'm not too keen on Regex. Is there some way that you could regex those find/replacements into just one find/replace? That would be best, I could just post on the forum "Hey guys, use N++ to find <blahblah> and replace it with [blahblah]." I assume not since, well, maybe it could -find- everything that i need to change, it's going to replace it with the same line of text.

    Also, when Irecorded the macro, I made a typo; I forgot the equal sign. I opened %AppData% Shortcuts.xml, manually edited the macro, saved it, and restarted N++. My changes were not saved, and my macro ran with the typo. I cut the entire macro out of shortcuts.xml and restarted NPP, and my macro was back. I deleted it within the app, then added the macro to shortcuts.xml. The macro never showed up after restarted NPP.

    This means that even when I make the macro work properly, I can't share it with anyone. =\

    Last edit: MyOhMyke 2013-03-12

    THEVENOT Guy - 2013-03-15

    Hi MyOhMike,

    I think I've got a solution for your specific SEARCH-REPLACEMENT !

    You MUST have Notepad++, since the 6.0 version, because
    we need the new PCRE regular expressions engine to achieve it !

    It's quite easy. No need for macros, plugins or scripts !


    • Open a NEW file, in a NEW TAB, in N++

    • Copy your THREE lines below ( your EXACT text )


    - Open the SEARCH-REPLACEMENT dialog with CTRL + H shortcut

    • Type in SEARCH                <(.*?)>(.*?)<.*

    • Type in REPLACEMENT    [SLOT_\U\1\E] = "\2",

    • Select the "Regular expression" search mode

    • Select the "Wrap around" box

    • Click on the "Replace All" button

    That's all !

    We get the REPLACED expressions :

    [SLOT_HEAD] = "Helm",
    [SLOT_BODY] = "Armor",
    [SLOT_HANDS] = "Gloves",

    Some NOTES :

    • In the SEARCH string :

    The block <(.*?)> stands for the SMALLEST string
    of characters BETWEEN < and >, contained in the
    group1, BETWEEN parenthesis ( the strings
    head, body, then hands )

    The block >(.*?)< stands for the SMALLEST string
    of characters BETWEEN > and <, contained in the
    group2, BETWEEN parenthesis ( the strings
    helm, armor, then gloves )

    the block .* stands for the REMAINDER of EACH
    line, from the / character, not used in REPLACEMENT

    - In the REPLACEMENT string :

    The block \U\1 represents the group1, in
    UPPER case and \E, which follows, CANCEL the

    The block \2 stands for the group no 2

    I hope, these explanations are useful to you !



    P.S. You can also find some documentation, about the new PRCE
    Regular Expressions
    , used by N++, since the 6.0 version,
    at the TWO adresses below :

    The FIRST one concerns the syntax of regular expressions in SEARCH

    The SECOND one concerns the syntax of regular expressions in REPLACEMENT

    Last edit: THEVENOT Guy 2013-03-15

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.

No, thanks