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

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -