I would like to extract the numbers in front of "OZ" and "CT"
For example
str = "CHOCOLATE ALMONDS 23OZ 12CT 589"
str2 = "CHOCOLATE ALMONDS 23 OZ 12 CT 3452"
I want to be able to extract 23 and 12 from str or str2 but ignore other numbers listed. The numbers can consist of any number of digits (can be 1, 12, 123, etc.)
I was thinking of using string.find('OZ')
and print the number before that based on the index but with that, I have to add logics that can tell the number of digits.
What is the most efficient way to do that? I'm new to Python, so any suggestions would be appreciated.
EDIT: This is NOT a duplicate of this question, as this one requires much more advanced searching than just to find all numbers in the string (as this string contains more numbers than what is requested to be found).