javascript - I need to match strings that don't contain a keyword at an arbitrary position -
i need match strings don't contain keyword (beta2
) @ arbitrary position.
consider:
var astr = [ '/beta1/foo', 'beta1/foo', '/beta1_xyz/foo', 'blahblah/beta1/foo', 'beta1', '/beta2/foo', 'beta2/foo', '/beta2_xyz/foo', 'blahblah/beta2/foo', 'beta2', '/beat2/foo', 'beat2/foo', '/beat2_xyz/foo', 'blahblah/beat2/foo', 'beat2' ]; function btestformatch (str) { return /.*\b(?!beta2).*/i.test (str); } (var j=0, ilen=astr.length; j < ilen; j++) { console.log (j, btestformatch (astr[j]), astr[j]); }
we need regex matches strings exclude beta2
. beta2
start @ word boundary, not end @ one. can @ variety of positions in string.
the desired results be:
0 true /beta1/foo 1 true beta1/foo 2 true /beta1_xyz/foo 3 true blahblah/beta1/foo 4 true beta1 5 false /beta2/foo 6 false beta2/foo 7 false /beta2_xyz/foo 8 false blahblah/beta2/foo 9 false beta2 10 true /beat2/foo 11 true beat2/foo 12 true /beat2_xyz/foo 13 true blahblah/beat2/foo 14 true beat2
the regex 3rd-party analysis tool takes javascript regular expressions filter sub-results. tool takes single line of regex. there no api , don't have access source-code.
is there javascript regex filter second beta results (beta2
) analysis run?
try
/^(?!.*beta2).*$/
Comments
Post a Comment