Regular Expressions 101

Community Patterns

ES6 Imports/exports/dynamic: Getting the paths

1

Regular Expression
ECMAScript (JavaScript)

/
(?:(?<=(?:import|export)[^`'"]*from\s+[`'"])(?<path1>[^`'"]+)(?=(?:'|"|`)))|(?:\b(?:import|export)(?:\s+|\s*\(\s*)[`'"](?<path2>[^`'"]+)[`'"])
/
gm

Description

It will match the paths of js modules imports, exports and dynamic imports.

Submitted by anonymous - 4 years ago