I would like to validate an input.
I want the input to be either blank, or allow for entries surrounded by single quotes separated by a comma, allowing for one, two, or more entries with any characters and any length between the single quotes. ex: 'one','two','three','\four','.dog','cat'
If I use this:
$string = Read-Host "Enter a string"
$pattern = "^$|^'\w+'(,'(\w+)')*$"
if ($string -match $pattern) {
Write-Host "The string meets the pattern."
} else {
Write-Host "The string DOES NOT meet the pattern."
}
For empty entry this works fine: ^$|
^'\w+'(,'(\w+)')*$ works for characters a-z,A-Z,0-9. But how do I allow for any character entry, including backslashes, periods and other special characters?
Thank you.