I had a good experience at the speed of regex in JS.
And I decided to make a small comparison. I ran the following code:
var str = "A regular expression is a pattern that the regular expression engine attempts to match in input text.";
var re = new RegExp("t", "g");
console.time();
for(var i = 0; i < 10e6; i++)
str.replace(re, "1");
console.timeEnd();
The result: 3888.731ms.
Now in C#:
var stopwatch = new Stopwatch();
var str = "A regular expression is a pattern that the regular expression engine attempts to match in input text.";
var re = new Regex("t", RegexOptions.Compiled);
stopwatch.Start();
for (int i = 0; i < 10e6; i++)
re.Replace(str, "1");
stopwatch.Stop();
Console.WriteLine( stopwatch.Elapsed.TotalMilliseconds);
Result: 32798.8756ms !!
Now, I tried re.exec(str); vs Regex.Match(str, "t");: 1205.791ms VS 7352.532ms in favor of JS.
Is massive text processing "Not suitable" subject to be done in .net?
UPDATE 1 same test with [ta] pattern (instead t literal):
3336.063ms in js VS 64534.4766!!! in c#.
another example:
console.time();
var str = "A regular expression is a pattern that the regular expression engine attempts 123 to match in input text.";
var re = new RegExp("\\d+", "g");
var result;
for(var i = 0; i < 10e6; i++)
result = str.replace(str, "$0");
console.timeEnd();
3350.230ms in js, vs 32582.405ms in c#.
result = str.replace(str, "1");= 3026.953ms\d+in a double quoted string for theRegExpconstructor, it is interpreted asd+(the non-sense escape is simply ignored and the next character is seen as a literal). To figure the\dcharacter class inside a double quoted string you have to use two backslashes:var re=RegExp("\\d+", "g");. Note that writingvar re=/\d+/g;orvar re=RegExp(/\d+/g);is exactly the same (none of these versions are compiled earlier or later.)