Menu

#1779 RegEx replace with forward-lookahead does not work

None
fixed
nobody
None
1
2016-09-21
2016-05-27
Markus
No

Consider the following document

abcd
abxy
abcd
abxy

I want to replace every 'ab' that is not followed by a 'c' to be replaced by '12'.

Steps to reproduce:

  1. Open Search/Replace (Ctrl+r)
  2. Activate RegEx-Mode by clicking the button
  3. Use search query "ab(?=[^c])"
  4. Use replacement "12"
  5. Search first occurrence using blue downarrow
  6. Hit replace (red downarrow)

Expected result: second line changes to 12xy
Actual result: nothing changes

  1. Hit replace all (red double downarrow)

Result: all correct occurrences are replaced (this is expected).

Discussion

  • Jan  Sundermeyer

    Jan Sundermeyer - 2016-05-27

    @Tim/Benito:
    the problem lies with following code:
    if (hasOption(Replace) && again && !all)
    if (m_regexp.exactMatch(m_cursor.selectedText())) {
    replaceCursorText(backward);
    updateReplacementOverlays();
    replaceCount++;
    }

    Any suggestions on how to resolve this ?

     

    Last edit: Jan Sundermeyer 2016-05-27
  • Tim Hoffmann

    Tim Hoffmann - 2016-05-28

    A correct handling is not possible just from the selection because the lookahead context is missing.
    Probably, one will have to

    if regexp contains lookahead or lookbehind:
        rematch the line until you find a match that results in the same selection
        if found:
            perform substitution
    
     
  • Tim Hoffmann

    Tim Hoffmann - 2016-06-12

    fixed: hg 6097 (bbb0cbdf3d1e)

    Side remark (semi-offtopic): Instead of a positive lookahead on a negated set ab(?=[^c]) you could have as well used a negative lookahead ab(?!c).

     
  • Tim Hoffmann

    Tim Hoffmann - 2016-06-12
    • status: open --> fixed
    • Group: -->
     
  • Carsten Wartmann

    Hi,

    not sure if this is good style, it seems for me the Bug is not fixed in texstudio-2.11.2-rc? Or it is another similar Bug, I suck at Regex... so...

       ABC DUF_GHI XYZ DAF-DOFGHU
       ABC DEF. GHI XYZ DAFTRE
       ABC DEF! GHI XYZDAFDHFDBF
    

    Try to replace in the project (normal replace works!) with

    RegEx: D.F (real expression is more complex)
    Replace: XXX

    Results in:

       ABC XXX__GHI XYZ  XXX-X-XXGHU
       ABC XXX.. GHI XYZ  XXXTRE
       ABC XXX!! GHI XYZZXXXXXXXXXXX
    
     
  • Jan  Sundermeyer

    Jan Sundermeyer - 2016-09-17

    works fine here
    I am not sure, what in your example is supposed to erroneous.

     
  • Carsten Wartmann

    There is a duplication of the last character after the replacement. Like"XXX__" where there should only one underscore. Even more weird at XXX-X-XXGHU which should be XXX-XXXGHU.
    As I said, I suck at RegEx but replacing with the normal replace works, only if using the extended replace for all Docs/Project etc. shows this....

     
  • Jan  Sundermeyer

    Jan Sundermeyer - 2016-09-21

    fixed, please , in future, open new bug reports for different bugs, especially since you originally forgot to mention that this only happens in in multi-doc replace

     
  • Carsten Wartmann

    Thanks Jan! Sorry for not beeing exact enough.

    EDIT: Just found that it is a manually process.

    --When will there be a binary? Is it a automatic process or does someone need to put it online manually?--

     

    Last edit: Carsten Wartmann 2016-09-21
  • Tim Hoffmann

    Tim Hoffmann - 2016-09-21

    The build process has to be started manually by us. There will be a release in the near future.

     

Log in to post a comment.

MongoDB Logo MongoDB