Avatar ·

How to remove all characters from a string except letters, digits, and hyphen in C#?

Hello everyone! I'm a beginner in C# and I've encountered a task: I need to clean a string from all characters except letters (Latin and Cyrillic), digits, and hyphen (-). For example, I have a string: ```csharp string input = "Hello-World! How are you? (test) 123-456 #2024"; ``` It should become: ``` Hello-World How are you test 123-456 2024 ``` That is, punctuation marks, spaces, brackets, hash signs, and everything else except letters, digits, and hyphen should be removed. I tried using `Regex.Replace` with the pattern `[^a-zA-Z0-9-]`, but it removes Cyrillic characters, and I need to keep them. If I add `а-яА-Я`, there are still some issues with spaces — they also get removed, but I need spaces to remain. Please advise how to correctly compose a regular expression or is there another way? Preferably