Regex to pull data from strings

Viewed 38

I have a column with random strings but I have to pull data from the string. A number with length 8 or greater.

These are the two strings:

x = "CHARGES*198953* 47694000 Brown * TFR"

y = "47694000 Koistin *    192333*UNSWORTH R* TFR"

Regex that work for y but not for x:

x1 = re.findall(r'^[1-9][0-9]{2,}',y)

I get nothing for x.

1 Answers

Try this instead:

x1 = re.findall(r'\d{7}\d+', x)

Result:

['47694000']
Related