# If you'd like to omit non-matching lines from the result; add ';d' to the end of the expression.
sed -E 's/import\s+(?:(?:([A-z_$][\w$]*)|\*\s+as\s+([A-z_$][\w$]*)|({\s*[A-z_$][\w$]*(?:\s+as\s+[A-z_$][\w$]*)?\s*(?:,\s*[A-z_$][\w$]*(?:\s+as\s+[A-z_$][\w$]*)?\s*)?}))\s+from\s+(("|'|`).*\5)|(("|'|`).*\7))/const $1$2$3 = require($4)/g;t' <<< "import defaultExport from \"module-name\";
import * as name from \"module-name\";
import { export1 } from \"module-name\";
import { export1 as alias1 } from \"module-name\";
import { export1 , export2 } from \"module-name\";
import { foo , bar } from \"module-name/path/to/specific/un-exported/file\";
import { export1 , export2 as alias2 } from \"module-name\";
import defaultExport, { export1 } from \"module-name\";
import defaultExport, * as name from \"module-name\";
import \"module-name\";
const module = await import(\"module-name\");"
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for SED, please visit: https://www.gnu.org/software/sed/manual/html_node/The-_0022s_0022-Command.html