0

Possible Duplicate:
Regex matching left single quotation outside the double quotations

First Note:

&ldquo - left double quote (")
&rdquo - right double quote (")
&lsquo - left single quote (')
&rsquo - right single quote (')

I need to match all "Left single quote" that are not inside of left and right double quote.

For clarricifcation:

  1. This is a “sample &lsquo string &rsquo &rdquo -> this should not be match because the &lsquo (single quotes) is inside the double quote

  2. This is a &lsquo sample &rsquo -> the &lsquo should be match because that is not inside the double quotation

Here's my current regex:

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

The problem with this is, it is looking both the &ldquo and &rdquo, if any of ldquo and rdquo occure, it will not match

for example:

  1. This is a &lsquo sample &rdquo -> I need to match &lsquo here but because of the appearance of &rdquo, the regex didn't match

  2. This is &ldquo a string &lsquo sample -> same problem with no.1 example

Hope somebody can help me! thanks!

Community
  • 1
  • 1
neo
  • 293
  • 3
  • 7
  • 21

1 Answers1

0

Untested but try this

(?<!&ldquo.*)&lsquo(?!.*&rdquo)
paparazzo
  • 44,497
  • 23
  • 105
  • 176