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:
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:
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: