-2

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!

neo
  • 293
  • 3
  • 7
  • 21
  • what about the `right single quote`.Is it there or not..Plz explain properly about what you actually want!With a list of **VALID** and **INVALID** examples... – Anirudha Aug 24 '12 at 06:20
  • I don't quite understand what you are trying to do here but I get a feeling that you are trying to parse a non regular expression. What happens if the quotes are nested and then nested again? – Jonas Elfström Aug 24 '12 at 06:47

3 Answers3

1

If I understood ur question..This may be what you want

(?<!&ldquo.*?)&lsquo(?!&rdquo)
Anirudha
  • 32,393
  • 7
  • 68
  • 89
0

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.

Derpy Derp
  • 429
  • 1
  • 5
  • 12
  • no, I need to match &lsquo that are not inside of &ldquo and &rdquo, for example, &lsquosample&rsquo &ldquosample text&rdquo. – neo Aug 24 '12 at 06:19
0

this is the right regex that I am looking at :

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

Thanks!

neo
  • 293
  • 3
  • 7
  • 21