I will use simple codes to describe my situation. For example, here are the codes:
using System;
using System.Text.RegularExpressions;
public class Example
{
public static void Main()
{
string pattern = @"\b(?!non)\w+\b";
string input = "Nonsense is not always non-functional.";
foreach (Match match in Regex.Matches(input, pattern, RegexOptions.IgnoreCase))
Console.WriteLine(match.Value);
}
}
Now, I would like to replace the "non" with a user input. Let say it's called "UserInput" and the codes are written perfectly for getting the user input. I want to do like this, but error exists:
string pattern = @"\b(?!{0})\w+\b", UserInput;
Is there any way to replace the "non" inside the pattern of regex with user input?