2

I have text as below-

my_text = "My telephone number is 408-555-1234"

on which i am searching the pattern

re.findall(r'\d{3}-\d{1,}',my_text)

My intention was to search for three digit numeric value followed by - and then another set of one or more than one digit numeric value. Hence I was expecting the result to be - ['408-555','555-1234'],

However the result i am getting os only ['408-555'] .

Could anyone suggest me what is wrong in my understaning here. And suggest a pattern that would serve my purpose

Jithin P James
  • 752
  • 1
  • 7
  • 23

1 Answers1

1

you can use:

re.findall(r'(?=(\d{3}-\d+))', my_text)

output:

['408-555', '555-1234']
kederrac
  • 16,819
  • 6
  • 32
  • 55