Forum Replies Created

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • in reply to: RegExp OR function misbehaviour ? #7635
    thr
    Member

    Yes, there were some typos in my posts. Also, I only tested the regular expressions through the Replace dialog. But I just created a macro containing this:

    document.selection.Replace("<(denk|wil|dacht|kan|wilde|ben|zie)je>","1 je",eeFindNext | eeReplaceAll | eeFindReplaceRegExp);

    Here at least, it works as expected.

    in reply to: RegExp OR function misbehaviour ? #7630
    thr
    Member

    Yes, a positive lookahead only matches, it doesn’t “consume” anything. But you can simplify your whole construct like so:

    document.selection.Replace("(<(denk|wil|dacht|kan|wilde|ben|zie)je>","1 je",eeFindNext | eeReplaceAll | eeFindReplaceRegExp);

    That way you don’t need to pay attention to matching the word separators at all. That gives you a lot more leeway. For example, you can then have something like

    denkje, wilje;dachtje-kanje
    wildeje/zieje

    and it will still work as intended, while keeping all word separators intact.

    Even more simpler with the word shorthand class:

    document.selection.Replace("(<(w+)je>","1 je",eeFindNext | eeReplaceAll | eeFindReplaceRegExp);
    in reply to: RegExp OR function misbehaviour ? #7628
    thr
    Member

    Try this:

    (rn| )(denk|wil|dacht|kan|wilde|ben|zie)je(?=rn| )

    The problem is that your original expression “consumes” both separators, at the beginning of a word and at the end of a word. If the separator at the end of the first word is “consumed” by the expression, it can’t be “consumed” by the expression that should match the second word. Using

    (?=rn| )

    performs a positive lookahead that only matches but doesn’t “consume” anything. You can write this even simpler, without having to use a positive lookahead, by using constraints (in this case beginning of a word and ending of a word):

    <(denk|wil|dacht|kan|wilde|ben|zie)je>
Viewing 3 posts - 1 through 3 (of 3 total)