How to match words in a string that are wrapped in curly brackets using RegEx with Python

1 Answer

0 votes
import re

text = "This is a {string} with {words} wrapped in {curly} brackets."

# Regex pattern to match words inside curly brackets
pattern = r'\{(.*?)\}'

# Find all matches
matches = re.findall(pattern, text)

print(matches)


'''
run:
 
['string', 'words', 'curly']
 
'''

 



answered Mar 17, 2025 by avibootz
...