-8

I would like to be able to get the string in between to words of my choice. For example :

x = "Hello My Name is John Doe"

I would like the program to return a string holding the values in between Hello and Doe - "My Name is John "

Thanks in Advance!

styvane
  • 59,869
  • 19
  • 150
  • 156

1 Answers1

1
import re
x = re.search("Hello (.*)Doe",
      "Hello My Name is John Doe")
if x:
    print x.groups()[0]
fugu
  • 6,417
  • 5
  • 40
  • 75