I need to insert a regular expression pattern:
$@"^(?:[^\p{{L}}]|[{exclusion}])+$" //Цель: Запретить использование каких либо букв в строке, кроме тех что заданы в переменной - exclusion string variable:
string exclusion; in which all control characters would be escaped, which would avoid errors associated with the operation of the regular expression.
I found the Regex.Escape() method. But he does not satisfy my needs. For example, if the value of exclusion = @"[text]" passed to the Regex.Escape() method, then it will return the string "\\[text]" . After inserting this line into a pattern instead of alternately exclusion:
$@"^(?:[^\p{{L}}]|[{exclusion}])+$" //Цель: запретить использование каких либо букв в строке, кроме тех что заданы в переменной - exclusion it takes the following form:
$@"^(?:[^\p{{L}}]|[\[text]])+$" As a result, the regular expression does not work correctly. I suspect that the reason for the extra character - ]
Please tell me how to escape all control characters in the string? Is there any other method besides the method - Regex.Escape ()? Maybe I somehow used it wrong and did not notice my mistake?
@- Grundy