Reputation: 55273
I had the following regex to match opening quotation marks:
/'(?=\b)/g
But then I realized that it also captures stuff like don't
and it's
.
So I added another rule:
/'(?=\b[^a-zA-Z])/g
Capture an opening quotation mark not followed by a letter (t
and s
in this case). But now none of the quotation marks are being highlighted.
Did I modify the regex in a wrong way?
EDIT:
Oh, I realized my dumb mistake. Anyway, here's what I want to do:
"two 'three'"
"four don't it's "
I want to match the opening '
in three
but not the '
s in don't
and it's
Upvotes: 0
Views: 254
Reputation: 32145
Referring to your last EDIT, this Regex /[\.\,\;\?\!\s]+'/g
is what you are looking for, it matches quotation in sentences like 'three'
and skips what you need (sentences like don't and it's
).
Upvotes: 1
Reputation: 338
You have your look-around in the wrong place. You want to find instances where a quote is preceded by nothing, and proceeded by characters. This would probably work
/\b'\B/
Upvotes: 2
Reputation: 16403
You can use the following regex to only match opening '
/(?!\b)'/g
See the demo on your testcases
Upvotes: 2
Reputation: 785098
You can try this regex to match quotes but skip those cases like don't
it's
etc:
/(?:^|[^a-zA-Z])'|'(?![a-zA-Z])/gm
Upvotes: 2