-3

I want to extract the no. 12 in this text. how can we achieve that? Here's the text.

 text = "Car Window Clip-on - Buy Here Pay Here (Blue) - Pack of 12"

the text is not fix but the pack of N is fix

Zhubei Federer
  • 1,274
  • 2
  • 10
  • 27

2 Answers2

1

You can use a regex search!

import re
text = "Car Window Clip-on - Buy Here Pay Here (Blue) - Pack of 12"

match = re.search(r"Pack of (\d+)", text)
if match:
    print(match.group(1))
flakes
  • 21,558
  • 8
  • 41
  • 88
0

You can use regex with lookbehind

import re

res = re.search('(?<=Pack of )\d+', text)
if res:
    print(res.group())
deadshot
  • 8,881
  • 4
  • 20
  • 39