I would like to match a string within some brackets. My string might have some apostrophes. I am using the following pattern for matching but this is not picking up the string and i don’t really see why – any idea?
pattern = re.compile('<([\w\s\']+)>', re.IGNORECASE)
e.g., <Let's rock!> would yield Let's rock!
You don’t have an apostrophe problem, you have an exclamation point problem. An exclamation point is neither word (
\w) nor whitespace (\s) nor an apostrophe. So you should add!to your character class if you want to allow it.