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:

posted @ Tuesday, June 08, 2010 8:19 PM

Print

Comments on this entry:

# re: Regular Expression to extract quoted text

Left by abcd muhammad at 8/8/2011 4:20 PM
Gravatar
blog.stpworks.com/.../...-extract-quoted-text.aspx
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:

# re: Regular Expression to extract quoted text

Left by information governance at 12/2/2011 12:26 AM
Gravatar
I work with a lot of data, both quantitative and qualitative, so input errors can be quite the headache. I have never used regular expressions, but wonder if used properly it can streamline the input process. Thanks for the suggestion.

Your comment:



 (will not be displayed)


 
 
 
Please add 5 and 6 and type the answer here:
 

Live Comment Preview: