const regex = /(?<topro>\([^)]*?\bpro +)(?<afterpro>.*?\))|(?<withoutpro>\(.*?\))/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('(?<topro>\\([^)]*?\\bpro +)(?<afterpro>.*?\\))|(?<withoutpro>\\(.*?\\))', 'gm')
const str = `4377631753733131 (pro alber con tr33)
886uhghsdfdsfh (pro cios tui tr32)
rtyqrey 6y46457 6372576 (Flrt ghnap tsr)
537657QQRFytyvg (flipzz Reyhdf frfg33)
4377631753733131 (pro alber con tr33) (flipzz Reyhdf frfg33) (foo pro bar pro cios tui tr32)
I would like all words after "pro" to be capitalized. If "pro" is not present, all words in the brackets must be lowercase, for have :
4377631753733131 (pro Alber Con Tr33)
886uhghsdfdsfh (pro Cios Tui Tr32)
rtyqrey 6y46457 6372576 (flrt ghnap tsr)
537657QQRFytyvg (flipzz reyhdf frfg33)`;
const subst = `${topro}\U${afterpro}\L${withoutpro}\E`;
// The substituted value will be contained in the result variable
const result = str.replace(regex, subst);
console.log('Substitution result: ', result);
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for JavaScript, please visit: https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions