2

According to the example in this ElasticSearch documentation page the following pattern matches values enclosed in double quotes:

"((?:\\"|[^"]|\\")*)"

Still I don't get the use of the second \\", which seems redundant. Any light?

Cavaz
  • 2,682
  • 19
  • 33
  • From what I see/comprehend, the entire alternation may not be necessary. +1 anyway to your question. – Tim Biegeleisen Aug 06 '18 at 11:19
  • I think maybe it's matching pairs of escaped quotes with anything non-quote in between, any number of times, until we hit a quote. – Ian Aug 06 '18 at 12:32
  • that's right. The question is: what is the rationale behind putting the escaped quote (`\\"`) twice in the OR? – Cavaz Aug 06 '18 at 12:41
  • Good point. Seems redundant to me too; certainly it makes no difference whether it's there or not in their example – Ian Aug 06 '18 at 13:06
  • I'm reasonably sure it doesn't serve any purpose being there, but I wouldn't call it redundant, exactly. Note that, "((?:\\"|[^"])*)" works, but "((?:[^"]|\\")*)" doesn't. I'd guess they tried the second one first, and had to puzzle out [why it didn't work](https://www.regular-expressions.info/alternation.html). – femtoRgon Aug 06 '18 at 17:44

0 Answers0