Cleanest may be KeySelect
and StringMatchQ
:
asc1 // KeySelect[StringMatchQ[#, "a.s.r*"] &]
<|"a.s.r" -> 1, "a.s.r345" -> 45, "a.s.r[4]/vu" -> 4|>
Responding to the follow-up questions in the comments:
Count[Keys @ asc1, s_String /; StringMatchQ[s, "a.s.r*"]]
3
asc1 // KeySelect[! StringMatchQ[#, "a.s.r*"] &]
<|"asc" -> "cas", "qwrs" -> 78, "es" -> 74|>
Also:
GroupBy[Normal@asc1, StringMatchQ[First@#, "a.s.r*"] &, Association]
<|True -> <|"a.s.r" -> 1, "a.s.r345" -> 45, "a.s.r[4]/vu" -> 4|>,
False -> <|"asc" -> "cas", "qwrs" -> 78, "es" -> 74|>|>
Or to modify asc1
in-place:
asc1 ~KeyDropFrom~ Keys[asc2];
asc1
<|"asc" -> "cas", "qwrs" -> 78, "es" -> 74|>