For example, I want to check if a file has only one extension. I tried to use the groups, but they don’t allow me to verify that they appear only once (I didn’t find out how to do it)
.(js|jsx)$
For example, if js and jsx are allowed:
test.js -> should match
test.jsx -> should match
test.ts -> should not match
test.js.jsx -> should not match
Any string with .js.jsx
, .jsx.jsx
, .jsx.js
or .js.js
at the end are not allowed.
2
Answers
.w+.w+
this regex expression matches files with more than one extension. However, it may be necessary to do some string operations first.Only one extension, means no
dot
before the extension, use[^.]
to specify any chars but notdot
. The full regular expression:But if you want to check if a file has only one allowed extension, you can use a global match:
Here is a example: