I have used Regex in C#. How do I use this type of Regex in Javasript. This type of regex works in C#.
I have the following Regex:
(?<Month>[A-Za-z]{3}) (?<Date>[0-9]{2}) (?<Hour>[0-9]{2}):(?<Minutes>[0-9]{2}):(?<Seconds>[0-9]{2}) (?<ComputerName>[A-Za-z0-9\-\ ]+): (?<KernalTime>[0-9\.\[\]\ ]+) (?<Message>[A-Za-z\(\)\.\ ]+)
to Parse the Following Line (All Lines are similar):
Nov 24 14:24:31 Dell-Inspiron-N5110 kernel: [ 0.000000] Intel GenuineIntel
In javascript i used the following code.
matchRegexParse: function () {
var myString = "Nov 24 14:24:31 Dell-Inspiron-N5110 kernel: [ 0.000000] Intel GenuineIntel";
var myRegexp = new RegExp(
"(?<Month>[A-Za-z]{3}) (?<Date>[0-9]{2}) (?<Hour>[0-9]{2}):(?<Minutes>[0-9]{2}):(?<Seconds>[0-9]{2}) (?<ComputerName>[A-Za-z0-9\-\ ]+): (?<KernalTime>[0-9\.\[\]\ ]+) (?<Message>[A-Za-z0-9\(\)\.\ \-\:]+)",
"gi");
var match = myRegexp.exec(myString);
alert(match);
},
I get the following Error (See Attached Image):
EDIT (ERROR AS TEXT):
Uncaught SyntaxError: Invalid regular expression:
/(?<Month>[A-Za-z]{3}) (?<Date>[0-9]{2}) (?<Hour>[0-9]{2}):(?<Minutes>[0-9]{2}):(?<Seconds>[0-9]{2}) (?<ComputerName>[A-Za-z0-9\-\ ]+): (?<KernalTime>[0-9.\[\]\ ]+) (?<Message>[A-Za-z0-9\(\)\.\ \-\:]+)/
: Invalid group