Skip to main content
deleted 14 characters in body
Source Link
ckhanna
  • 3.7k
  • 1
  • 1
  • 12

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.

enter image description hereenter image description here

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.

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 = "^([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"
}elseif($input -match $underScoreRegex){
    Write-Host "The input string contains only underScore"
}else{
    Write-Host "The string does not matches any of the criterias"  
} 

This is the output returned through above script.

enter image description here

Using above regex, 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.

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.

enter image description here

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.

Source Link
ckhanna
  • 3.7k
  • 1
  • 1
  • 12

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 = "^([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"
}elseif($input -match $underScoreRegex){
    Write-Host "The input string contains only underScore"
}else{
    Write-Host "The string does not matches any of the criterias"  
} 

This is the output returned through above script.

enter image description here

Using above regex, 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.