Regular Expression to extract quoted text

If you have a text enclosed with single or double quotes and optionally containing escaped quotes inside the text, the following regular expression will help you to extract the text:

(['"])(?<text>.*?)(?<!\\)\1

For example, parsing text:

'Hello world' 
'World\'s test'
"World's test"

will yield following results:

Hello world
World\’s test
World’s test

Technorati Tags: