You could use a capture group that will be returned by re.findall.
Note that to get the lowercase output, you should not use txt.upper()
You can make the pattern case insensitive using re.I
\(((?:NASDAQ|NYSE)[^()\s]*)\)
The pattern matches:
\( Match (
( Capture group 1
(?:NASDAQ|NYSE) Match either NASDAQ or NYSE
[^()\s]* Match 0+ occurrences of any char except ( and ) or a whitspace char
) Close group 1
\) Match )
Regex demo | Python demo
For example
import re
txt = "(NASDaq/abnjnxd:number1) ojsnxsjsxmjosx (nasDaq:number2) (NYSE:bhdnd) (Nasdaq:eres)"
x = re.findall("\(((?:NASDAQ|NYSE)[^()\s]*)\)", txt, re.I)
print(x)
Output
['NASDaq/abnjnxd:number1', 'nasDaq:number2', 'NYSE:bhdnd', 'Nasdaq:eres']
A more precise pattern could be matching an optional part that starts with a / and word characters, followed by matching : and word characters.
\(((?:NASDAQ|NYSE)(?:/\w+)?:\w+)\)
The pattern matches:
\( Match (
( Capture group 1
(?:NASDAQ|NYSE) Match either NASDAQ or NYSE
(?:/\w+)? Optionally match / and 1+ word chars
:\w+ Match : and 1+ word chars
) Close group 1
\) Match )
Regex demo
(?:NASDAQ|NYSE).*?:.*?(?=\)). Demo: regex101.com/r/9aNcdi/1re.findall(r"(?i)\b(?:NASDAQ|NYSE)\b[^:()]*:[^)]*", txt)(?<=\()[^)]*(?=\)). See it here at Regex101.