This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
The right regex makes it quite easy. You need just three parts to it:
- positive lookbehind for (. Note that you must escape the (
- a reluctant quantifier for the contents
- positive lookahead for ). Again, escape it.
Using Regex, you need a pattern with three constructs,
1) A matching opening parenthesis
2) Match any character until it matches a closing parenthesis
3) A matching closing parenthesis
To get you start with: 1) To match a character, you just need to have that character in the pattern string. Watch out for meta characters which need to be escaped.
2) To match any character, the meta character '.' (dot) is used.
3) To match a character zero or more times, the meta character '*' (asterisk) is used
4) To extract a subset of data from the regex, you can use something called 'groups'. In your case, the parenthesis' are used to just match and you are interested in the data in between them; so you can capture the data as a group.