try -replace
to delete substrings by regex patterns
PS> $string1="abc_xyz-mnq_R81"
PS> $string2="abc_xyz-mnq_R82"
PS> $string1 -replace "^.*_R"
81
PS> $string2 -replace "^.*_R"
82
0
solved Unable to trim string in PowerShell
try -replace
to delete substrings by regex patterns
PS> $string1="abc_xyz-mnq_R81"
PS> $string2="abc_xyz-mnq_R82"
PS> $string1 -replace "^.*_R"
81
PS> $string2 -replace "^.*_R"
82
0
solved Unable to trim string in PowerShell