Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

18
  • 11
    @steve: this would also match, incorrectly, "foo\". The look ahead trick makes the ? quantifier possessive (even if the regex flavor doesn't support the ?+ syntax or atomic grouping) Commented Sep 11, 2014 at 13:33
  • 4
    A version using named variables: ((?<openingQuote>["'])(?<contents>(?:(?=(?<escapedContent>\\?))(?P=escapedContent).)*?)(?P=openingQuote)) Commented Feb 22, 2016 at 12:46
  • 18
    This returns the values including the matching quotes. Is there no chance to return only the content between the quotes, as it was requested? Commented Sep 13, 2016 at 11:19
  • 22
    Abusing a lookahead as a possessive quantifier is completely unnecessary and confusing. Just use an alternation: (["'])(?:\\.|[^\\])*?\1 Commented May 23, 2018 at 16:13
  • 11
    A modified version of this that only matches the content between the quotes excluding the quotes themselves: (?<=(["']))(?:(?=(\\?))\2.)*?(?=\1) Commented Aug 6, 2020 at 15:50