vba - Regex to Replace text without using lookbehind -
i have text file several items (blocks of text) following:
sample item_id sample_id_0000028 blah blah abcd <--- not remove blah blah blah blah blah blah sample_end sample item_id sample_id_0000033 other text more text abcd <--- remove more text sample_end sample item_id sample_id_00041 abcd <--- not remove blah blah blah blah sample_end
i want replace/remove instance of abcd
occurs in item id sample_id_0000033
. challenge there other instances of abcd
in file want leave alone. also, number of lines between item_id
, abcd
varies item item, , it's possible abcd
not found in specified item.
i must manipulate file via vbscript in vba. figured use regex this, vba not support regular expressions lookbehind. there pattern can used accomplish negative lookahead or simpler that?
i execute regex on string defined textfile.readall
, textfile
textstream.
you can use this:
pattern: (item_id sample_id_0000033\d(?:[^s]|s(?!=ample_end))+?)abcd replace: $1
or better, this:
pattern: (item_id sample_id_0000033\d(?:[^\r]+\r\n)+?)abcd replace: $1
or shorter acheong87 example:
pattern: (sample_id_0000033\d(?:[^\r]+\r\n)+?)abcd replace: $1
Comments
Post a Comment