Skip to content

Commit b78c46b

Browse files
committed
Improved regex documentation
1 parent 7ba48ec commit b78c46b

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

index.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,14 @@ module.exports = function concat(entryModule, outputFile, opts, cb) {
148148
fs.readFile(filePath, {"encoding": "utf8"}, this);
149149
}, function processFile(code) {
150150
// Scan file for `require(...)`, `__dirname`, and `__filename`
151-
var requireRegex = /require\s*\(\s*(\s*["'])((?:(?=(\\?))\3.)*?)\1\s*\)/g,
151+
/* Quick notes about the somewhat intense `requireRegex`:
152+
- require('...') and require("...") is matched
153+
- The single or double quote matched is group 1
154+
- Whitespace can go anywhere
155+
- The module path matched is group 2
156+
- Backslashes in the module path are escaped (i.e. for Windows paths)
157+
*/
158+
var requireRegex = /require\s*\(\s*(["'])((?:(?=(\\?))\3.)*)\1\s*\)/g,
152159
dirnameRegex = /__dirname/g,
153160
filenameRegex = /__filename/g;
154161
code = code.replace(requireRegex, function(match, quote, modulePath) {

0 commit comments

Comments
 (0)