我正在开发一个尝试一些正则表达式的函数。让我解释。
function traitement
{
if ($Matches.NAME -match "^A_(?<test1>[\w{1,6}]{1,7})")
{
[void]($memberOfCollection.add($Matches.test1))
}
elseif ($Matches.NAME -match "^A_(?<test2>[]*)")
{
[void]($memberOfCollection.add($Matches.test2))
}
else
{
[void]($memberOfCollection.add($Matches.NAME))
}
}
我有$Matches.NAME
返回字符串"A_UserINTEL"
,如“A_UserINTELASUS"
或"A_UserINTEL_Adobe"
我需要区分来自的 2 个字符串$Matches.NAME
,因此需要编写几个测试。
"A_UserINTEL"
并且"A_UserINTELASUS"
必须返回"UserINTEL"
。"A_UserINTEL_Adobe
"必须返回"UserINTEL_Adobe"
Test1 允许我检索"UserINTEL"
,但我没有成功 test2 带给我"UserINTEL_Adobe"
。
任何想法?谢谢你。