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-._]*)$"
$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 dashes"
}elseif($input -match $dashRegex){
Write-Host "The input string contains only dashes"
}else{
Write-Host "The string does not matches any of the criterias"
}
This is the output returned through above script.
Using above Powershell
snippet, the first condition will only be true
when string contains both the characters i.e. undersore as well as dashes(in any order) and second condition returns true
only when string contains dash characters.
Hope this helps!!! Let me know in case you have any queries.