You can use below Powershell snippet
to check whether the string contains underscore and dashes or the string contains only dashes.
$underScoreDashRegex = "^([a-zA-Z0-9-._]*[-]+[a-zA-Z0-9-._]*[_]+[a-zA-Z0-9-._]*)|([a-zA-Z0-9-._]*[_]+[a-zA-Z0-9-._]*[-]+[a-zA-Z0-9-._]*)$"
$underScoreRegex$dashRegex = "^([a-zA-Z0-9-.]*[-]+[a-zA-Z0-9-.]*)$"
$input = "video_thumb-4721086006001"
if($input -match $underScoreDashRegex){
Write-Host "The input string contains underScore as well as dash"dashes"
}elseif($input -match $underScoreRegex$dashRegex){
Write-Host "The input string contains only underScore"dashes"
}else{
Write-Host "The string does not matches any of the criterias"
}
This is the output returned through above script.
Using above regexPowershell
snippet, the first condition will only be truetrue
when string contains both the characters i.e. undersore as well as dashes(in any order) and second condition returns truetrue
only when string contains dash characters.
Hope this helps!!! Let me know in case you have any queries.