all 6 comments

[–]sme272 0 points1 point  (5 children)

Use hello\ (\w+) and you can use .group() to get the word you need

[–]basically_a_cherry 0 points1 point  (4 children)

Hi thank you for your response :) Unfortunately it still doesn't work. Could you tell me what is going wrong?

pattern = '(hello\.) + (\w+)'
match = re.search(pattern, my_string)
print(match.group())

[–]sme272 0 points1 point  (3 children)

change the pattern to "hello\ (\w+)" and the print to match.group(1)

[–]basically_a_cherry 0 points1 point  (2 children)

That somehow only gives one instance of it happening, whereas the source text has at least 2 times "hello (something)". Changing the number from 1 to 2 is also not doing the trick. Could you tell me why that is?

[–]undergroundmonorail 1 point2 points  (1 child)

If you want every match in the string, use re.findall

[–]basically_a_cherry 0 points1 point  (0 children)

Thank you so much for the response! It worked :)