Regex to match strings inside brackets with no spaces around
问题 I'm using the following regex to match strings inside brackets: \((.*?)\) But this matches this: (word) and this too: ( word ) I need to modify it to only match the first case: words inside brackets with no spaces around: (word) Any ideas? Thanks in advance 回答1: Use lookahead/lookbehind to disallow space after the opening parenthesis and before the closing parenthesis: \((?!\s)[^()]+(?<!\s)\) (?!\s) and (?<!\s) mean "not followed by / not preceded by a space". The part in the middle, [^()]+