Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 23160

How to match a string not surrounded by brackets and parenthesis using regex

$
0
0

I have a collection of strings that take, for example, the following form:

(GOOGL)  [ST]S (partial) 02/01/2024 03/01/2024 $1,001 - $15,000(PHG)  [ST]P 02/12/2024 03/01/2024 $1,001 - $15,000(PFE)  [ST] P 02/12/2024 03/01/2024 $1,001 - $15,000(UL)[ST]S 02/12/2024 03/01/2024 $1,001 - $15,000

I'd like to find a pattern to return the thirdmost group of characters (eg, 'S' in the first line) not surrounded by brackets or parens for each row.

The below pattern gets me each of the capitalized character strings (eg, GOOG, ST, S):

([A-Z]+)

How would I only return the 'S', 'P', 'P', and 'S' from each line respectively, which will never be surrounded by parentheses or brackets (alternatively, will have at least one of, sometimes both, a space before or after)?


Viewing all articles
Browse latest Browse all 23160

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>