Hi folks,
in my C# program, I have a regular expression textparser, that finds all occurrences of words that are surrounded by double squared brackets. For instance, [[anything]] would find the word anything.
In a second step, I want to count how often the found word (in my example: anything) appears in the whole text. To do this, I try to create a RE that contains the found word and count, how many matches I get. Problem is, that the found word can also contain special chars and the following regex:
string foundWord = "(anything";
Regex countOccurences = new Regex(foundWord);
will obviously fail when the variable contains special chars like '('. Expresso suggests for matching whole expressions the following construct:
Regex countOccurences = new Regex("(?(" + foundWord + ")Yes|No)");
but when in this scenario foundWord is a number, like '2009', the RE tries to interpret it as a reference to a group (which is obviously not defined). In my text, there can be any combination of normal chars, special chars, numbers etc.
How can I tell the RE to interpret the given string as literal expression only?
Thanks in advance, Frank