问题
Note :
left double quotation (") = &ldquo
right double quotation (") = &rdquo
left single quotation (') = &lsquo
My current regex is this
(?<!.*&ldquo.*)&lsquo
It matches the &lsquo in here (which is right):
&ldquoThis is a sample&rdquo &lsquosample text
It also matches the &lsquo in here (which I don't want to happen because the single quote is inside the left and right double quote):
&ldquoThis &lsquois a sample&rdquo
How can I write a regex that will match every &lsquo that are NOT inside the left and right quotation
Thanks for all your help!
回答1:
If I understood ur question..This may be what you want
(?<!&ldquo.*?)&lsquo(?!&rdquo)
回答2:
Use ASCII escape sequence to tell the regex which characters are you referring to.
\x93
- Refers to &ldquo\x94
- Refers to &rdquo
So the regex you need is: [\x93]*[^x94]
Or if your you know what characters your string consists of, then: [A-Za-z0-9\x93]*[^x94]
, and so on. Add more characters as per your need.
回答3:
this is the right regex that I am looking at :
(?<!.*“)‘(?!.*”)
Thanks!
来源:https://stackoverflow.com/questions/12103448/regex-matching-left-single-quotation-outside-the-double-quotations