Hacker News new | past | comments | ask | show | jobs | submit login

Intersection with the complement will not work here.

Because the idea is to match Tarzan, but only if it is not preceded and followed by a quote.

Regex intersection and complement do not perform look-behind or trailing context.

Live demo:

  This is the TXR Lisp interactive listener of TXR 265.
  Quit with :quit or Ctrl-D on an empty line. Ctrl-X ? for cheatsheet.
  TXR may be used in areas that are not necessarily well   ventilated.
  1> [#/Tarzan&~"Tarzan"/ "Jane shouted, \"Tarzan\""]
  "Tarzan"
  2> [#/Tarzan&~"Tarzan"/ "Jane shouted, \"Tarzan!\""]
  "Tarzan"
The &~"Tarzan" makes absolutely no difference. The reason is that Tarzan matches exactly one string. The complement ~"Tarzan" matches a whole countable infinity of strings, and one of those is Tarzan. The intersection of that infinity and Tarzan is therefore Tarzan.

Intersection with complement is useful like this:

Search for a three-character substring that is not cat:

  3> [#/...&~cat/ "hat"]
  "hat"
  4> [#/...&~cat/ "dog"]
  "dog"
  5> [#/...&~cat/ "doggy"
  "dog"
  6> [#/...&~cat/ "cat"]
  nil
  7> [#/...&~cat/ "scatter"]
  "sca"
  8> [#/...&~cat/ "catalan"] ;; "cat" is skipped, then "ata" works.
  "ata"



Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: