3 ms·
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 inters
by kazinator 5y ago
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"