Search a array for a string “-like” in another array?

I have the following situation with a array of strings, one of the arrays the text is seperated by underscore, the other by spaces:

$mygroups1=@("THIS_IS_A_EXAMPLE_TYPEA_TYPE1_GROUP", THIS_IS_A_EXAMPLE_TYPEA_TYPE2_GROUP", THIS_IS_A_EXAMPLE_TYPEB_GROUP", THIS_IS_A_EXAMPLE_TYPEC_TYPE1_GROUP", THIS_IS_A_EXAMPLE_TYPEC_TYPE2_GROUP" ) $mygroups2=@("I am TypeA Type1", "I am TypeA Type2", "I am TypeB", "I am TypeC Type1", "I am typeC type2", "I am TypeD Type1", "I am TypeD Type1", ) foreach ($group2 in $mygroups2) { foreach ($group1 in $mygroups1) { if ($group1 -like $group2) { Write-Host "Yay" } } } 

The text I am looking for and trying to match is the “TYPEA_TYPE2″/”TYPEB”/etc part

I thought that would work but…

I need to find if one of the strings in one of the arrays is in the other array. Since they do not start and end the same, a like will be enough.

A split might not solve the issue because I might have THIS_IS_A_EXAMPLE_TYPEB_GROUP but i also have THIS_IS_A_EXAMPLE_TYPEE_TYPE1_SUBTYPEZ_GROUP

I also cannot length it: “TypeB” is obviously a example but real world can be …”THIS_IS_A_EXAMPLE_sjhdfjshdgj” while another can be “THIS_IS_A_EXAMPLE_sjd_sdj_xs_qw_we”.

Does anyone have any clever Powershell ideas? Thanks.

submitted by /u/riahc4
[link] [comments]

Leave a Reply