-
Notifications
You must be signed in to change notification settings - Fork 0
/
sample.cs
45 lines (35 loc) · 1.06 KB
/
sample.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
using System;
using System.Linq;
using System.Net.Http;
using System.Reflection;
using WebAssembly;
using WebAssembly.Net.Http.HttpClient;
using System.Text.RegularExpressions;
using Wasm; // FIXME better namespace naming?
namespace Regexr
{
public static class Program
{
public static void EvaluateRegex(string pattern, string testString, JSObject outputElement)
{
string output;
try
{
var sb = new System.Text.StringBuilder();
Regex regex = new Regex(pattern);
var matches = regex.Matches(testString);
sb.AppendLine($"Got {matches.Count} matches:\n");
foreach (Match match in matches)
{
sb.AppendLine(match.Value);
}
output = sb.ToString();
}
catch (Exception ex)
{
output = $"Error evaluating regex: {ex}";
}
outputElement.SetObjectProperty("innerText", output);
}
}
}