Search code examples
replaceemeditor

Match 1 or more words separated by comma


I want to match in Emeditor any 1 or more word(s) or phrases (that follow a specific language name) separated by comma and ending in semicolon.

For example, I would like to match this string for Russian:

Russian: радость сть, весе-веселье, весе' веселье, веселье;

And create wiki links in the replacement like this:

Russian: [[радость сть]], [[весе-веселье]], [[весе' веселье]], [[веселье]];

This is the example text:

Bulgarian: веселие, радост; Chinese Mandarin: 歡笑, 欢笑, 愉快, 高興, 高兴; Dutch: vrolijkheid; Finnish: ilo, hilpeys; French: gaieté; Georgian: მხიარულება, სიმხიარულე, სიხარული; German: Fröhlichkeit, Belustigung, Freude; Greek: ευθυμία, κέφι; Ancient Greek: εὐφροσύνη; Italian: gran gioia, allegria; Japanese: 笑い, 遊び, 喜び, 歓楽; Malayalam: ആഹ്ലാദം; Plautdietsch: Freid; Portuguese: alegria, júbilo; Russian: радость сть, весе-веселье, весе' веселье, веселье; Scottish Gaelic: sogan; Spanish: felicidad, alegría, júbilo; Swedish: munterhet, glädje


Solution

  • Just a couple of lines in the EmEditor macro should do it. 1st line identifies the language and selects that line, 2nd line makes the replacement. e.g. :

    v3

    document.selection.Find("(^|; )((Russian: )|(Ancient Greek: )|(Greek: )|(French: ))\\K[^;]*(?=$|;)",eeFindNext | eeFindReplaceCase | eeFindReplaceRegExp | eeFindSelectAll,0);
    
    document.selection.Replace("(\\b[^,;]+)(?=$|,)","[\\1]",eeFindReplaceCase | eeFindReplaceSelOnly | eeReplaceAll | eeFindReplaceRegExp,eeExFindBOL | eeExFindEOL);