About merging two regular expressions in javascript
世界只因有你
世界只因有你 2017-06-12 09:28:45
0
2
727

When using karma for code coverage testing, remove main.js

// require all src files except main.js for coverage.
// you can also change this to match only the subset of files that
// you want coverage for.
const srcContext = require.context('../../src', true, /^\.\/(?!main(\.js)?$)/)
srcContext.keys().forEach(srcContext)

Later I added a style folder, which contains scss files, and I also want to remove this folder too

ss = ["./main.js","./style","./maaa.js","./style/sss.scss"]

ss.forEach(function(s){
console.log(s)
console.log(/^\.\/(?!main(\.js)?$)/.test(s))
console.log(/^\.\/(?!style.*)/.test(s))
console.log(/^\.\/(?!main(\.js)?$) | ^\.\/(?!style.*)/.test(s))
})
./main.js
false
true
false
./style
true
false
false
./maaa.js
true
true
false
./style/sss.scss
true
false
false

The two separate regular expressions seem to be correct, but using | together does not achieve the expected effect. There is really no other way. Please help me.

世界只因有你
世界只因有你

reply all(2)
代言

Remove the extra spaces in the middle and enclose | in parentheses on both sides.

我想大声告诉你

Just enclose the body of the regular expression with "[]"
For example:

console.log(/^[\.\/(?!main(\.js)?$)|^\.\/(?!style.*)]/.test(s))
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!