There are several ways, upon the type of ID.
If they have same prefix, suffix, create a segment, start with, end with
Or, search from Dimension, select all of the 40 IDs, drag & drop into "segment" interface
If there are even more, e.g. hundreds of IDs, you may need to download all the values and filter, then upload back to Adobe Analytics to re-classify them as an individual dimension.