Regular expression negative match
问题 I can't seem to figure out how to compose a regular expression (used in Javascript) that does the following: Match all strings where the characters after the 4th character do not contain "GP". Some example strings: EDAR - match! EDARGP - no match EDARDTGPRI - no match ECMRNL - match I'd love some help here... 回答1: Use zero-width assertions: if (subject.match(/^.{4}(?!.*GP)/)) { // Successful match } Explanation: " ^ # Assert position at the beginning of the string . # Match any single