Let me first mention that this a well discussed problem and I have gone through several thread including these two - which are closest match Regex to match a string not followed by some string and A regex to match a substring that isn't followed by a certain other substring but they did not solve my problem.
I have strings containing volume and quantity in several different formats -mentioned below, e.g. 6 X 200ml mean 6 packs of 200 milliliters each. I want to extract only the quantity like 6 in the this example
Examples
- blah 6 X 200ml -- 6
- blah 200 mlX 6 -- 6
- blah x 5000 ml -- 0 or better 1
- blah x 500000ml -- 0 or better 1
- blah 5mlX10 -- 10
- blah 500 mlX 10 -- 10
This is what I've tried so far without any success
(X\s*\d+|\d+\s*X)(?!\s*ml)
it matches case #3 and 4 as well which shouldn't be matched. I am also fine with extracting quantity like 6 with multiplication sign e.g 6 X instead of just 6. I can replace it.