I want to implement a JavaScript RegEx that not ending with (.js|.jsx|.scss), execution result like below, but no operator !
before RegEx.
!/(.js|.jsx|.scss)$/
I want to implement a JavaScript RegEx that not ending with (.js|.jsx|.scss), execution result like below, but no operator !
before RegEx.
!/(.js|.jsx|.scss)$/
You need to use a negative look ahead with alternations to reject the strings that end with those extensions you mentioned in your post. Try this regex,
^(?!.*(?:\.jsx?|\.scss)$).*$
var arr = ['abc.js','xyz.jsx','ddd.scss','abc.jsa','xyz.jsxa','ddd.scssd'];
for (s of arr) {
console.log(s+' --> '+/^(?!.*(?:\.jsx?|\.scss)$).*$/.test(s));
}
You can use this
^(?!.*\.(?:jsx?|scss)$).*$
^
- Anchor to start of string.(?!.*\.(?:jsx?|scss)$).*
- Condition to check jsx, js and scss
$
- End of string.