Description
Given a comma delimited string if multi digit numbers or a string with a single multi-digit number, you could use this regex to replace the leading comma and the numbers evenly divisible by 3
or 5
with null.
(?:,|^)((?:[0369]|[258][0369]*[147]|[147](?:[0369]|[147][0369]*[258])*[258]|[258][0369]*[258](?:[0369]|[147][0369]*[258])*[258]|[147](?:[0369]|[147][0369]*[258])*[147][0369]*[147]|[258][0369]*[258](?:[0369]|[147][0369]*[258])*[147][0369]*[147])*|[0-9]*[50])(?=,|\Z)
a more detailed explanation of this expression can be found here: see also link
Replace with:
nothing

Example
Live Demo
https://regex101.com/r/iG9lP4/1
Sample string
1,2,3,5,9,15,16,21,23,25
After replacement
1,2,16,23
Explanation
NODE EXPLANATION
----------------------------------------------------------------------
(?: group, but do not capture:
----------------------------------------------------------------------
, ','
----------------------------------------------------------------------
| OR
----------------------------------------------------------------------
^ the beginning of a "line"
----------------------------------------------------------------------
) end of grouping
----------------------------------------------------------------------
( group and capture to \1:
----------------------------------------------------------------------
(?: group, but do not capture (0 or more
times (matching the most amount
possible)):
----------------------------------------------------------------------
[0369] any character of: '0', '3', '6', '9'
----------------------------------------------------------------------
| OR
----------------------------------------------------------------------
[258] any character of: '2', '5', '8'
----------------------------------------------------------------------
[0369]* any character of: '0', '3', '6', '9'
(0 or more times (matching the most
amount possible))
----------------------------------------------------------------------
[147] any character of: '1', '4', '7'
----------------------------------------------------------------------
| OR
----------------------------------------------------------------------
[147] any character of: '1', '4', '7'
----------------------------------------------------------------------
(?: group, but do not capture (0 or more
times (matching the most amount
possible)):
----------------------------------------------------------------------
[0369] any character of: '0', '3', '6', '9'
----------------------------------------------------------------------
| OR
----------------------------------------------------------------------
[147] any character of: '1', '4', '7'
----------------------------------------------------------------------
[0369]* any character of: '0', '3', '6', '9'
(0 or more times (matching the most
amount possible))
----------------------------------------------------------------------
[258] any character of: '2', '5', '8'
----------------------------------------------------------------------
)* end of grouping
----------------------------------------------------------------------
[258] any character of: '2', '5', '8'
----------------------------------------------------------------------
| OR
----------------------------------------------------------------------
[258] any character of: '2', '5', '8'
----------------------------------------------------------------------
[0369]* any character of: '0', '3', '6', '9'
(0 or more times (matching the most
amount possible))
----------------------------------------------------------------------
[258] any character of: '2', '5', '8'
----------------------------------------------------------------------
(?: group, but do not capture (0 or more
times (matching the most amount
possible)):
----------------------------------------------------------------------
[0369] any character of: '0', '3', '6', '9'
----------------------------------------------------------------------
| OR
----------------------------------------------------------------------
[147] any character of: '1', '4', '7'
----------------------------------------------------------------------
[0369]* any character of: '0', '3', '6', '9'
(0 or more times (matching the most
amount possible))
----------------------------------------------------------------------
[258] any character of: '2', '5', '8'
----------------------------------------------------------------------
)* end of grouping
----------------------------------------------------------------------
[258] any character of: '2', '5', '8'
----------------------------------------------------------------------
| OR
----------------------------------------------------------------------
[147] any character of: '1', '4', '7'
----------------------------------------------------------------------
(?: group, but do not capture (0 or more
times (matching the most amount
possible)):
----------------------------------------------------------------------
[0369] any character of: '0', '3', '6', '9'
----------------------------------------------------------------------
| OR
----------------------------------------------------------------------
[147] any character of: '1', '4', '7'
----------------------------------------------------------------------
[0369]* any character of: '0', '3', '6', '9'
(0 or more times (matching the most
amount possible))
----------------------------------------------------------------------
[258] any character of: '2', '5', '8'
----------------------------------------------------------------------
)* end of grouping
----------------------------------------------------------------------
[147] any character of: '1', '4', '7'
----------------------------------------------------------------------
[0369]* any character of: '0', '3', '6', '9'
(0 or more times (matching the most
amount possible))
----------------------------------------------------------------------
[147] any character of: '1', '4', '7'
----------------------------------------------------------------------
| OR
----------------------------------------------------------------------
[258] any character of: '2', '5', '8'
----------------------------------------------------------------------
[0369]* any character of: '0', '3', '6', '9'
(0 or more times (matching the most
amount possible))
----------------------------------------------------------------------
[258] any character of: '2', '5', '8'
----------------------------------------------------------------------
(?: group, but do not capture (0 or more
times (matching the most amount
possible)):
----------------------------------------------------------------------
[0369] any character of: '0', '3', '6', '9'
----------------------------------------------------------------------
| OR
----------------------------------------------------------------------
[147] any character of: '1', '4', '7'
----------------------------------------------------------------------
[0369]* any character of: '0', '3', '6', '9'
(0 or more times (matching the most
amount possible))
----------------------------------------------------------------------
[258] any character of: '2', '5', '8'
----------------------------------------------------------------------
)* end of grouping
----------------------------------------------------------------------
[147] any character of: '1', '4', '7'
----------------------------------------------------------------------
[0369]* any character of: '0', '3', '6', '9'
(0 or more times (matching the most
amount possible))
----------------------------------------------------------------------
[147] any character of: '1', '4', '7'
----------------------------------------------------------------------
)* end of grouping
----------------------------------------------------------------------
| OR
----------------------------------------------------------------------
[0-9]* any character of: '0' to '9' (0 or more
times (matching the most amount
possible))
----------------------------------------------------------------------
[50] any character of: '5', '0'
----------------------------------------------------------------------
) end of \1
----------------------------------------------------------------------
(?= look ahead to see if there is:
----------------------------------------------------------------------
, ','
----------------------------------------------------------------------
| OR
----------------------------------------------------------------------
\Z before an optional \n, and the end of
the string
----------------------------------------------------------------------
) end of look-ahead
----------------------------------------------------------------------