Regex matching left single quotation outside the double quotations

旧街凉风 提交于 2019-12-31 07:41:57

问题


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 :

(?<!.*&ldquo;)&lsquo;(?!.*&rdquo;)

Thanks!



来源:https://stackoverflow.com/questions/12103448/regex-matching-left-single-quotation-outside-the-double-quotations

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!