Thanks Abigail, I have realised the problem of my mistake, where the double space is matched as "space + not <". My previous regular expression should really be written as /_test\s+(?![\s|<])/, as "space not followed by another space or <". Thanks for your help!