In Chrome and any other environment that supports the ECMA2018 standard, you can use the backward preview block:
console.log("=小校袦袦(A18:I18)".match(/(?<![A\d])18(?!\d)/g)) console.log("=小校袦袦(A18:I18)".replace(/(?<![A\d])18(?!\d)/g, "<孝校孝>$&</孝校孝>"))
Details
(?<![A\d]) - immediately before 18 there should not be A or numbers18 - 18(?!\d) - right after 18 there should not be a digit
In other cases, you have to solve the problem with the help of exciting groups:
var s = "=小校袦袦(A18:I18)"; var rx = /([A\d])?18(?!\d)/g; console.log(s.replace(rx, function ($0, $1) { return $1 ? $0 : "<孝校孝>" + $0 + "</孝校孝>" }))
Here ([A\d])? - optional exciting group, it finds an A or a number. If this pattern captures text, the group 1 buffer is non-empty and in this case, the match 18 is valid. If the verification of the first group fails, the match is considered not found.
+in regular expression. Plus, 18 are now displayed, which are afterA- Grundy/[^A](18)/g? - And/(?<![A\d])18(?!\d)/g? - Wiktor Stribi偶ew