using System;
using System.Text.RegularExpressions;
public class Example
{
public static void Main()
{
string pattern = @"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))";
string substitution = @"const $1$2$3 = require($4)";
string input = @"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"");";
Regex regex = new Regex(pattern);
string result = regex.Replace(input, substitution);
}
}
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 C#, please visit: https://msdn.microsoft.com/en-us/library/system.text.regularexpressions.regex(v=vs.110).aspx