const regex = /((.*)\/(.*)\/(.*) (.*):(.*):(.*)) (\[(error)\]) (\[(.*)\]) (([\t\n])?((?:[^\t\n]*[\t\n])+.*)|(.*))/;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('((.*)\\\/(.*)\\\/(.*) (.*):(.*):(.*)) (\\[(error)\\]) (\\[(.*)\\]) (([\\t\\n])?((?:[^\\t\\n]*[\\t\\n])+.*)|(.*))', '')
const str = `2015/10/06 19:20:27 [error] [php] Trying to get property of non-object (/www/ussd/protected/components/Process.php:267)
Stack trace:
#0 /www/ussd/vendor/yiisoft/yii/framework/yiilite.php(3570): CInlineAction->runWithParams()
#1 /www/ussd/vendor/yiisoft/yii/framework/yiilite.php(3555): TestController->runAction()
#2 /www/ussd/vendor/yiisoft/yii/framework/yiilite.php(3545): TestController->runActionWithFilters()
#3 /www/ussd/vendor/yiisoft/yii/framework/yiilite.php(1746): TestController->run()
#4 /www/ussd/vendor/yiisoft/yii/framework/yiilite.php(1666): CWebApplication->runController()
#5 /www/ussd/vendor/yiisoft/yii/framework/yiilite.php(1191): CWebApplication->processRequest()
#6 /www/ussd/index.php(22): CWebApplication->run()
REQUEST_URI=/test/?dialog_id=32&ussd_text=*152%23&msisdn=995557231065&service_code=152`;
// Reset `lastIndex` if this regex is defined globally
// regex.lastIndex = 0;
let m;
if ((m = regex.exec(str)) !== null) {
// 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