Regular expression a or b

How to make a regex that matches only r.js or build.js, but not to router.js (for example)?
I did this: /^r.js$|^build.js$/ , but I feel there is a way to remove ^ and $. If I delete them, router.js will match.

+4
source share
1 answer

Try:

 /^(r|build)\.js$/ 

'' should be avoided. If ^ is deleted, it will match router.js, if $ is removed, it will match r.jsx. Therefore, they are necessary.

+6
source

All Articles