I have the below regex, which currently allows '_' but not '-'.
string validCharacters = @"^\w+$";
Regex.Match(componentName, validCharacters);
But I want to also to include '-' as a valid character. The '-' can be at any place in the string. i,e: first,last,middle,after '_' etc.
Below are the few test cases:
"DTD_rtop-234"
"DTD-rtop_234"
"-DTD_rtop-234"
"DTD_rtop-234-"
"DTD_-rtop-234"
Any help will be much appreciated.