-2

In Excel VBA regular expresson, how can match a double quote but need to ignore pair of double qoute? Thanks all.

Tried lookahead, lookbehind that might not meet the target. Such as ^(?!.*"".*).*".*$ This will ignore 2 or more double quote even 3 or 5. Which is not expected because it is not a pair.

Match

  • 123"456
  • 123"456"789
  • 123"""456"""789

Don't match

  • 123""456
  • 123""456""789
  • 123456789
Chiting
  • 1
  • 1

1 Answers1

0

Try this: ^(?!.*"").*".*

Explanation:

^: Start of line

(?!): Negative lookahead. Check to see if the string in the brackets matches. The match is cancelled if it does.

.*"": Any number of characters followed by two quote marks. The match is cancelled if this is found.

.*".*: The negative lookahead guarantees no double quotes are found, so just look for a single quote encased in any number of characters on either side.

dc-ddfe
  • 487
  • 1
  • 11
  • Thanks. It works if there is 1 double quote, but not work if there is 3 double quote (added the case in question). – Chiting Dec 12 '22 at 06:40
  • I just tried ^([^"]|"")*$ then inverse the result, it seems work but I don't know how it work. – Chiting Dec 12 '22 at 06:43