const regex = new RegExp('[\\t:]*(from (.*?)[ ]*|)import (.*?)(| as (.*?))[\\n]', 'gm')
const str = `import os
import os as test
from RegistryController import RegistryController
from ui.windows.lists import ListCtrl, DynamicListCtrl
from main.core import Exceptions
from Queue import Queue
from main.core.MessageQueue import Queue as MessageQueue
from os import test as test
for i in range(50):import os
import os
for i in range(50):
import os
print("We are importing this new, import ajid.")`;
// Reset `lastIndex` if this regex is defined globally
// regex.lastIndex = 0;
let m;
while ((m = regex.exec(str)) !== null) {
// This is necessary to avoid infinite loops with zero-width matches
if (m.index === regex.lastIndex) {
regex.lastIndex++;
}
// The result can be accessed through the `m`-variable.
m.forEach((match, groupIndex) => {
console.log(`Found match, group ${groupIndex}: ${match}`);
});
}
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 JavaScript, please visit: https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions