EBlake
EBlake

Reputation: 755

Regex to search for literal match followed by text not containing a second literal

I want to match for the following sequences (all case-insensitive):

The last condition is the problem for me.

I am performing the searches in Sublime 3 (uses Perl/Boost regex syntax?)

I have unsuccessfully tried modifying the solution given at javascript regex match word not followed by pattern with text inbetween

The best I've come up with is

call[\t ]+?_(?:(?!boot).){4,}?

but this has dependency on the number of characters in the function name.

The purpose of this search is to search through a bootloader dis-assembly listing to make sure that it is not calling any functions outside the bootloader memory space (all blessed function have the text "boot" in their name). The underscore comes from the compiler name-mangling.

Sample text (the hits are marked HIT)

 88811 000294  00 A0 A9         bclr.b    _RCONbits,#5    ;,
 88813 000296  00 00 07         call    _vBootInitSerialBuffer    ;
 88815 000298  F0 0E 20         mov    #239,w0    ;,
 88816 00029a  00 00 07         rcall    _vBootInitSerial_C1    ;
 88818 00029c  F0 0E 20         mov    #239,w0    ;,
 88819 00029e  00 00 07         rcall    _vBootInitSerial_C2    ;
 88821 0002a0  00 40 EB         clr.b    w0    ; tmp38
 88822 0002a2  00 E0 B7         mov.b    WREG,_gbTurnOnLED    ; gbTurnOnLED
 89049 00032e  E0 0F 50         sub    w0,#0,[w15]    ; tmp56,
 89050      Call the routine
 89051 000330  00 00 3A         bra    nz,.L50    ;
 89053 000332  10 C0 B3         mov.b    #1,w0    ;,
 89054 000334  00 00 07         rcall    _memcpy    ;  <HIT>
 89055 000336  00 00 37         bra    .L50    ;
 89054 000334  00 00 07         rcall    _BxootGGashLED    ; <HIT>
 89055 000336  00 00 37         bra    .L50    ;
 89054 000334  00 00 07         rcall    _BootFlashLED    ;
 89054 000334  00 00 07         call    _ln    ; <HIT>
 89055 000336  00 00 37         bra    .L50    ;
 89054 000334  00 00 07         call    _vBoootFlashLED    ; <HIT>
 89055 000336  00 00 37         bra    .L50    ;
 89054 000334  00 00 07         rcall    _u8BootGGashLED    ;
 89055 000336  00 00 37         bra    .L50    ;
 89054 000334  00 00 07         rcall    _u16bootGGashLED    ;
 89055 000336  00 00 37         bra    .L50    ;
 89056                  .L49:
 89058 000338  00 00 80         mov    _gu16_50HzTimerTick,w0    ;

Upvotes: 0

Views: 113

Answers (1)

Tim Pietzcker
Tim Pietzcker

Reputation: 336128

You can simplify your regex:

r?call[\t ]+_(?!.*boot).*

will match from call or rcall until the end of the line if no boot is encountered along the way (in which case it fails to match entirely).

Don't forget to set the case-insensitive modifier (or add a (?i) to the start of the regex).

Test it live on regex101.com.

Upvotes: 1

Related Questions