lookaround and other nasty words ultraedit 12.?

lookaround and other nasty words ultraedit 12.?

1

    Feb 07, 2008#1

    Hi all,

    I am trying to do the following (ultraedit 12.?) :

    Remove (replace with an empty string, or maybe a space) all of the instances of <br> in a string UNLESS they occur between THEN and ENDCASE or DEFAULT and ENDDEFAULT.

    So

    {SELECT {[Liste1]} <br>CASE "3case" <br> THEN 1<br> ENDCASE<br>CASE "1" THEN 2 ENDCASE<br> DEFAULT Default<br> a moi ENDDEFAULT<br>
    ENDSELECT}


    Should end up

    {SELECT {[Liste1]} CASE "3case" THEN 1<br> ENDCASE CASE "1" THEN 2 ENDCASE DEFAULT Default<br> a moi ENDDEFAULT
    ENDSELECT}


    I was thinking that lookaround was the way to go but nothing I try (and I won't bother you with the 10s of useless expressions I've tried!) gets me anywhere...

    If there are any true demons out there, then what we really need to end up with is something that will do the following...

    {SELECT {[Liste1]} <br>CASE "3case" <br> THEN 1 {SELECT {[Liste1]} <br>CASE "3case" <br> THEN 1<br> ENDCASE<br>CASE "1" THEN 2 ENDCASE<br> DEFAULT Default<br> a moi ENDDEFAULT<br>
    ENDSELECT} ENDCASE<br>CASE "1" THEN 2 ENDCASE<br> DEFAULT Default<br> a moi ENDDEFAULT<br>
    ENDSELECT}

    Goes to :

    {SELECT {[Liste1]} CASE "3case" THEN 1 {SELECT {[Liste1]} CASE "3case" THEN 1<br> ENDCASE CASE "1" THEN 2 ENDCASE DEFAULT Default<br> a moi ENDDEFAULT
    ENDSELECT} ENDCASE CASE "1" THEN 2 ENDCASE DEFAULT Default<br> a moi ENDDEFAULT
    ENDSELECT}


    So in fact the <br> can/should be removed between THEN and ENDCASE (and DEFAULT and ENDDEFAULT) but ONLY if the <br>s are within a {SELECT...ENDSELECT}, and within that the normal rules should apply...

    Am I as clear as mud?

    Any help or abuse most appreciated!

    Cheers

    Anton

    236
    MasterMaster
    236

      Feb 07, 2008#2

      Without having read your post thoroughly, there are two things you should know: First, positive lookaround is and always has been broken in UE. Finding matches works, but replacing doesn't. I have been telling that to support since V12, and so far I have always received the reply "We know the problem, and we will fix it some day". Negative lookaround does work correctly.

      Second, lookbehind only allows for a fixed number of characters (i.e. no * or + etc.). That's a limitation of Perl regexes as a whole, not UE's fault. So your second example couldn't be done in a regex with lookaround even if UE's Perl regex engine would work fully correct.

        Feb 07, 2008#3

        OK, now let's see. I need some more info since the sample is so small:

        Is there any restriction on what can be between THEN and ENDCASE or between DEFAULT and ENDDEFAULT? Especially other tags besides <br>? Could THEN/ENDCASE and DEFAULT/ENDDEFAULT be nested (THEN ... DEFAULT...ENDDEFAULT ... ENDCASE or THEN ... THEN ... ENDCASE ... ENDCASE?)

        Will the potential matches (i.e. those where you want to preserve the <br>) always be on one line or can there be line breaks in-between?

        I'm quite confident that this can be solved. Can you also attach a longer sample file with your answer?

        Cheers,
        Tim