I don't completely get what you mean, but I can show you how to make the regex:
// step1: take the string, and escape it (hint: there's a function for this)
$regex = 'onclick="pcm_popup_open\(2, \'Something\'\)"';
// step2: replace the number, you can limit it with: {minLength,maxLength}
$regex = 'onclick="pcm_popup_open(([0-9]){1,}, \'Something\')"';
// step3: replace the string
$regex = 'onclick="pcm_popup_open(([0-9]){1,}, \'(a-zA-Z0-0]+)\')"';