Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Powershell: how to check if string contains any significant characters?

I need to check a string to see if it conatins anything other than spaces, returns, etc.

In perl, I used:

if($val =~/^\s*$/) {...}

How do I do that in PowerShell?

like image 373
Jeff Avatar asked May 03 '13 21:05

Jeff


1 Answers

Use the -match operator:

if ($test -match 'regex_here') { 'It matched' }

Also check the online docs for comparison operators: http://technet.microsoft.com/en-us/library/hh847759.aspx

like image 93
Andy Arismendi Avatar answered Sep 19 '22 13:09

Andy Arismendi