I am struggling with working out a way to get a pattern match of a variable. I have tried splitting things and doing an indexOf, using match, and a switch (true) statement, all with little success. Any help would be appreciated!
currentExports = 'sec=sys,rw=badhost1.foo.com:badhost2.foo.com,root=badhost1.foo.com:badhost2.foo.com';
badExportHosts = params.badExportHosts.split(':');
for (badHost = 0; badHost < badExportHosts.length; badHost++) {
if (!currentExports.match(/badExportHosts[badHost]/g)) {
printf('Entry ' + badExportHosts[badHost] + ' was not found in ' + currentExports + '\n');
} else {
printf('Entry ' + badExportHosts[badHost] + ' was found in ' + currentExports + '\n');
}
If I enter into my form:
badhost1.foo.com:badhost2.foo.com
I unfortunately get this result:
Entry badhost1.foo.com was not found in sec=sys,rw=badhost1.foo.com:badhost2.foo.com,root=badhost1.foo.com:badhost2.foo.com
Entry badhost2.foo.com was not found in sec=sys,rw=badhost1.foo.com:badhost2.foo.com,root=badhost1.foo.com:badhost2.foo.com
How can I get this to match?
I think your intention here doesn’t seem clear enough, but, if I understood it correctly, and all you want is to check wether your “badHost” strings are contained anywhere on currentExports, you could try replacing this:
for this: