re = /‘(?!(?:“[^”\n]*”|[^‘”\n])*’(?![a-z]))/mi
str = '“double-quote,” and some text
Some text and “double-quote” and an ‘orphan
“double-quote,” some text and ‘matched l/rsquo’
Some text and “double-quote” and an ‘orphan and an ’elided word
“double-quote,” ‘matched l/rsquo’ and an ‘orphan and ’elided word
Some text, “double-quote,” more text, an ‘orphan and a contract’n
“double-quote,” some text, and another “double quote.”
“double-quote,” some text, an ‘orphan and “another double-quote”
“double-quote,” a ‘matched l/rsquo with an “embedded double-quote” in it.’
“double-quote,” a ‘matched l/rsquo with an “embedded double-quote” in it’ and an ‘orphan.
“double-quote,” some text, an ‘orphan, a contract’n, and “another double-quote”
“double-quote,” some text, another “double-quote,” an ‘orphan and a contract’n
“double-quote” and “another double-quote” and an ‘orphan and ‘another lsquo
“double-quote” and some text and an ‘orphan and ‘a matched l/rsquo’
Some text and “double-quote” and an ‘orphan and ‘a matched l/rsquo with a contract’n’
some text and an ‘orphan
some text and an ‘orphan and an ’elided word
some text and an ‘orphan and a contract’n
some text ‘orphan, another ‘lsquo, and more text
some text ‘orphan, a contract’n, another ‘lsquo and ’elided word and more text
some text, an ‘orphan and a “double-quote with ‘matching l/rsquo’” and more text
Some text, “double quote, with an ‘orphan inside.”
Some text, “double quote, with a ‘matched l/rsquo inside.’”
Some text, “double quote, with an ‘orphan and contract’n inside.”
Some text, “double quote, with an ‘orphan and ’elided word inside.”
Some text, “double quote, with an ‘orphan and ‘matched l/rsquo inside.’”
“‘Orphan immediately following double-quote.”
“‘Matching l/rsquo immediately inside double-quote.’”
“‘Orphan immediately following double-quote with ‘matched l/rsquo’ inside.”
“Double quote,” another “double quote with an ‘orphan and ‘matched l/rsquo’”
“double quote,” another “double quote with an ‘orphan and contract’n and ‘matched l/rsquo’ and more text”'
# Print the match result
str.scan(re) do |match|
puts match.to_s
end
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Ruby, please visit: http://ruby-doc.org/core-2.2.0/Regexp.html