Regexp not picking up as expected
I am running this regexp to move text frames containing certain words or characters to a layer called Hypertext. When I run the following code it is skipping some text frames that contain underscores. Can someone tell me what I am doing incorrectly here?
#target illustrator-22
var doc = app.activeDocument;
var allText = doc.textFrames;
var allLayers = doc.layers;
var check = 0;
var layerName = "Hypertext"
var newFillColor = new CMYKColor();
newFillColor.black = 0;
newFillColor.cyan = 0;
newFillColor.magenta = 100;
newFillColor.yellow = 100;
var titleBar = "Increase Font?";
var increaseFontPrompt = prompt("Do you want to increase the font size of text moved to the Hypertext layer for easy checking?\ny = yes\nn = no", "y", titleBar);
for (i = 0; i < allLayers.length; i++) {
if (allLayers.name == "Hypertext") {
check++;
}
}
if (check == "0") {
createAndName();
}
// create Hypertext layer
function createAndName() {
var myLayer = allLayers.add();
myLayer.name = layerName;
}
var targetLayer = doc.layers.getByName("Hypertext");
for (var i = allText.length - 1; i >= 0; i--) {
var textFieldRange = allText.textRange;
/* REGEXP of what to move and what to skip */
if (allText.contents.match(/_|(STARTER(?!\s))|BLOCK AS|(\W(SW(?![A-Z])))|HOURMETER|G7P|CD700|PM410|RELAY|KEYPAD/g) != null &&
allText.contents.match(/SEAL_CAP|CBL_|_CABLE|THIS SCHEMATIC|SWEEP|FLOOD|FLD|LAMP|BEACON|(N.O.)|(N.C.)|(PIN)/g) == null) {
// increase the font and make it red if it matches the regexp
if (increaseFontPrompt == "y" | increaseFontPrompt == "Y" | increaseFontPrompt == "yes" | increaseFontPrompt == "Yes") {
textFieldRange.characterAttributes.size = "14";
textFieldRange.characterAttributes.fillColor = newFillColor;
}
allText.move(targetLayer, ElementPlacement.PLACEATEND);
}
}
alert("Anything with an underscore has been moved \rto the Hypertext layer.\rReview and cleanup content accordingly. \rNot all components contain underscores and \rsome will need to be moved manually.");
Here is the actual file I am running it on. I have highlighted with yellow boxes the text frames that are not being picked up that I think should be.
https://drive.google.com/open?id=1NAppe5-rnwRdXIt4fnfthoXykOQM_Hf7