0

I am looking for some help to put a REGEX expression together that will return the contents between ROUTINE and END_ROUTINE

I have tried

ROUTINE S[0-9]{1,5}_[A-Z0-9_]* ([\s\S]*)?(?=END_ROUTINE

)

But it doesnt seem to provide the correct output

        ROUTINE S7026_HMI_LB0_SP_MAX 
            RC: "===================================================================================================$N"
                "$N"
                "Local HMI Station B Setpoint Commands Max Clamp$N"
                "$N"
                "===================================================================================================";
            N: NOP();
    END_ROUTINE

    ROUTINE S0100_DIAGNOSTICS 
            N: JSR(S0101_PLC_Diagnostics,0);
            N: JSR(S0102_IO_Diagnostics,0);
    END_ROUTINE
Ken White
  • 123,280
  • 14
  • 225
  • 444

1 Answers1

0

It could be enough to add a modifier U to make it ungreedy.

/ROUTINE(.+)END_ROUTINE/sU

(you can test it here: https://regex101.com/r/U2MM6G/1)

Alternatively, you can also do this more specifically:

/ROUTINE(.+?)END_ROUTINE/s

bvdb
  • 22,839
  • 10
  • 110
  • 123