c# - Replacing all occurrences of alphanumeric characters in a string -
i'm trying replace alphanumeric characters in string character "-" using regex. if input "dune" should "----". though i'm getting single "-";
string s = "^[a-za-z0-9]*$"; regex rgx = new regex(s); string s = "dune"; string result = rgx.replace(s, "-"); console.writeline(result); console.read();
right know looking string "dune" rather letters "d" "u" "n" "e". can find class work.
your regex greedy, remove * , start end string matches. should be
string s = "[a-za-z0-9]";
this match 1 character anywhere in string rather all. @ shorthand alphanumeric
string s= "\w";
Comments
Post a Comment