select concat(',',concat_ws(',',A),',') regexp
concat(',(',concat_ws('|',B),'),') as are_common_elements
from mytable
;
Demo
create table mytable (id int,A array<string>,B array<string>);
insert into table mytable
select 1,array('P908','S57','A65'),array('P908','S57')
union all select 2,array('P908','S57','A65'),array('P9','S5777')
;
select * from mytable;
+------------+----------------------+----------------+
| mytable.id | mytable.a | mytable.b |
+------------+----------------------+----------------+
| 1 | ["P908","S57","A65"] | ["P908","S57"] |
| 2 | ["P908","S57","A65"] | ["P9","S5777"] |
+------------+----------------------+----------------+
select id
,concat(',',concat_ws(',',A),',') as left_side_of_regexp
,concat(',(',concat_ws('|',B),'),') as right_side_of_regexp
,concat(',',concat_ws(',',A),',') regexp
concat(',(',concat_ws('|',B),'),') as are_common_elements
from mytable
;
+----+---------------------+----------------------+---------------------+
| id | left_side_of_regexp | right_side_of_regexp | are_common_elements |
+----+---------------------+----------------------+---------------------+
| 1 | ,P908,S57,A65, | ,(P908|S57), | true |
| 2 | ,P908,S57,A65, | ,(P9|S5777), | false |
+----+---------------------+----------------------+---------------------+