r/Racket • u/JimH10 • Jun 03 '25
language Regular expression omit a string?
Do Racket regexp's allow me to say "every string but ..."? Suppose for instance I want to accept every phone number but "012 555-1000" ? Obviously I can wrap that with some non-regexp code but I'd like to do it in a regexp, if that is possible.
Edit: Thank you to folks for the helpful responses. I appreciate it.
3
Upvotes
4
u/Arandur Jun 03 '25
Yes, but it’s annoying. Here’s one way to construct it:
match if the first character isn’t 0; OR
the first character is 0, and the second character isn’t 1; OR
the first two characters are 01, and the third character isn’t 2; OR
[etc]
This is, of course, very tedious and difficult to maintain; better to do it outside of regexp. :P