I have a Javascript regex that tokenizes words from a sentence which is like the following:
/\\[^]|\.+|\w+|[^\w\s]/g
Like if a sentence is entered like
Hello World.the above regex will tokenize it into words:
Hello,World,.
I am trying to convert the above regex in C#, but its not able to group it. I have tried removing the / and the \g from the beginning and the end respectively, in order to make it compatible with .NET regex engine. But its still not working.
Below is the C# code I am trying:
public static void Main()
{
string pattern = @"\\[^]|\.+|\w+|[^\w\s]";
string input = @"hello world.";
foreach (Match m in Regex.Matches(input, pattern, RegexOptions.ECMAScript))
{
Console.WriteLine("'{0}' found at index {1}.", m.Value, m.Index);
}
}
Can anyone help me converting the above regex into C#?