Home > OS >  PYTHON | Extracting specific text from variable [regex]
PYTHON | Extracting specific text from variable [regex]

Time:12-01

I have this text: Intel Core i5-1235U 3.3GHz (10C 12T • 12MB Cache • up to 4.4GHz)

and i want to extract everything after the word "Core" till the next backspace "i5-1235U"

the pattern of the text can be changed, like Intel Core i7-1255U 3.3GHz (10C 12T • 12MB Cache • up to 4.4GHz) where I want the "i7-1255U"

or Intel Core i7-920P 3.3GHz (10C 12T • 12MB Cache • up to 4.4GHz) where I want the "i7-920P"

and so on..

it will always start with "Intel Core" and will have "x.xGhz" after the word I want to extract

i5?. U

but it works specifically with "Intel Core i5-1235U 3.3GHz (10C 12T • 12MB Cache • up to 4.4GHz)" and I want it to work on many variations :(

CodePudding user response:

You can try code below:

text = 'Intel Core i7-920P 3.3GHz (10C 12T • 12MB Cache • up to 4.4GHz)'

cpu_type = (text.split('Core')[1]).split()[0]
  • Related