Reputation: 63
I new in regex and i want to find a good solution for replacing whitespace before or after the /
char in my sub string.
I have got string like
"Path01 /Some folder/ folder (2)"
i checked regex
@"\s?()\s?"
but this incorrect for me. I must get in output
Path01/Some folder/folder (2)
Can you help me?
Thanks!
Upvotes: 4
Views: 5507
Reputation: 626690
You may use
@"\s*/\s*"
and replace with /
.
See the regex demo
The pattern matches zero or more (*
) whitespace chars (\s
), then a /
and then again 0+ whitespace chars.
C#:
var result = Regex.Replace(s, @"\s*/\s*", "/");
Upvotes: 5