0

I have a following code:

test_string = "Hello Hello World World"
pattern = "Hello World".replace(" ","[\w\W]+")
match = re.search(pattern, test_string)
print(match)

The output is Hello Hello World World but not Hello Hello World

What can I change so that regex stops when it find the 1st World?

Tried several regex expression but still confused

1 Answers1

0

pattern = "Hello World".replace(" ","[\w\W]+?")

Solved the solution. Thanks!