Problems using non-capturing groups in Perl-style regexes

Product Compare Forums Multi-Edit Support Problems using non-capturing groups in Perl-style regexes

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #2995
    Bret Sutton
    Participant

    I’m running ME v11.04 on 64-bit Windows 7.

    This regular expression:[code:1tbi4ns3](?m)string1[^\r\n]*?(\r?\n[^\r\n]*?){x,y}string2[/code:1tbi4ns3] allows me to find instances of string 1 and string2 that are separated by an arbitrary number of lines (in this case, between x and y lines). (In use, of course, I would use appropriate values for string1, string2, x, and y.)

    Note that the regex makes use of grouping parentheses. I do not want that group to be captured. So I add a "?:":[code:1tbi4ns3](?m)string1[^\r\n]*?(?:\r?\n[^\r\n]*?){x,y}string2
    [/code:1tbi4ns3]However, that causes the search to fail. Why?

    Second question: Suppose I make an alias <n-lines> that is defined as [code:1tbi4ns3][^\r\n]*?(\r?\n[^\r\n]*?)[/code:1tbi4ns3]I can then change my find to [code:1tbi4ns3](?m)string1<n-lines>{x,y}string2[/code:1tbi4ns3]or, for only a single line of separation,[code:1tbi4ns3](?m)string1<n-lines>string2[/code:1tbi4ns3] However, this search, although it should be functionally equivalent to the first find above, which works, always fails. Why?

    #9676
    Bret Sutton
    Participant

    At this point, I’m more interested in getting the alias working than in solving the non-capturing-group problem.

    And the obvious answer is that Multi-Edit is having difficulties substituting the aliased expression into the user’s find string. This appears to be implemented in the search.s and regexp.s macro files.

    My search.s and regexp.s are quite different from the original. Many of the changes are udpates from ME staff, but some are mine (for example, the implementation of a case-matching replace). I will check my changes to verify that I have not inadvertently introduced this error. But I would appreciate confirmation from you as to whether the problems I noticed also occur for you.

    #9678
    Clay Martin
    Keymaster

    Hi Bret,
    The second search string that you supplied ( which failed) worked for me.
    [code:2m0dqa1f](?m)string1[^\r\n]*?(?:\r?\n[^\r\n]*?){x,y}string2[/code:2m0dqa1f]

    I also created the alias you provided (although I set the alias name as <nlines> versus <n-lines> as I felt having the – might be problematic). It also worked as expected.
    [code:2m0dqa1f](?m)Clay<nlines>{2,5}Lori[/code:2m0dqa1f]

    So It seems that the problem might be in the changed CMac code you have.

    Clay

    #9683
    Bret Sutton
    Participant

    I tried all of this on my home computer. Worked fine.

    I finally got around to trying it again at work. Worked fine. :oops:

    I have noticed that, every so often on my work machine, Multi-Edit will not do something as expected. Typically, it’s a search. Tonight, it wasn’t showing the Find 1 tab after I did a search across files. If I close Multi-Edit and restart it, the problem goes away. I guess this regex problem was one of those. Until I have more information, there’s nothing I can throw up to you.

    Thanks for your help.

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