Quick Tip: Detecting Special Characters In A String The Easy Way

Here’s a super easy way to detect special characters in a string. Consider the following.

String1 has no special characters, String2 does. All I’m doing is comparing the string to “the string if we replace everything that isn’t a regular letter” using the -replace operator.

It’s just that easy.

You could do the same thing with the -match operator, too. The point here is looking at the regex.

Leave a Reply

Your email address will not be published. Required fields are marked *