I just need to match parentheses around some content that has to match specific criteria. I need to match only the parentheses so that I can then do a quick replacement of only those parentheses and keep their content.
For the moment, what I have matches those specific parentheses, but unfortunately also their contents: \((?:\d{2,7})\)
The criteria for matching parentheses are as following:
- only match parentheses that contain
\d{2,7}
I have tried positive lookahead (\((?=\d{2,7})\)
), and while it does indeed not consume whatever follows the open parenthesis, it then fails to match the closing parenthesis as it backtracks to before the content...
So yeah, any help would be appreciated :)
Copyright Notice:Content Author:「Skwiggs」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/40086706/regex-match-parentheses-without-matching-their-contents