I’m having problems with the Replace function for a string, with regex.
I’m trying to escape all characters except numbers and text.
The second Replace function is working properly (I need to escape everything except text). I can’t seem to find the problem, or difference between the two functions.
→ the output stays the same as the input (even if I change the output variable to a new)
→ the output is as expected
I have this saved to remove Specials only (keeping numbers and text)
So you could try that one.
The one-liner would look like this:
System.Text.RegularExpressions.Regex.Replace(text, “[^\w\d]+”, “”)
Thank you for putting me on the right track.
Your solution still let the underscores pass.
I used this eventually: [^a-zA-Z0-9]
Good thinking using [^a-zA-Z0-9]
I didn’t know it would leave underscores; I will remember that next time. Thanks.
Can you help me in replacing 1/2 or 2/2 or 10/10 these are page numbers of a pdf and I will not know how many pages . so I need to use this and can you advice how to use it.