How to extract string number based on the listed values using regex in python?


This Content is from Stack Overflow. Question asked by James Lin


Id      Prod
xisos   clor 12Oz pack of 12
kasos   zemd 13 Oz pack of 1
oaldd   lb24 pk 12
odldf   12-ct kalsj 19992
jsdkl   OZ 32 ksldj 45 x 76

I need to fetch the sizes from prod with the logic, where ever I see the listed pattern [Oz, oz,…lb] I will fetch the numbers which appears before or after the listed units.

Id      Prod                      Size
xisos   clor 12oz pack of 12      12
kasos   zemd 13 Oz pack of 1      13
oaldd   lb24 pk 12                24
odldf   12-ct kalsj 19992         12
jsdkl   OZ 32 ksldj 45 x 76       32


This question is not yet answered, be the first one who answer using the comment. Later the confirmed answer will be published as the solution.

This Question and Answer are collected from stackoverflow and tested by JTuto community, is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?