Few strata of geekery are more obsessive than regular-expression geekery. So let’s have some fun! In https://www.tbray.org/ongoing/When/202x/2024/09/22/Unbackslashing I explain why using the usual backslash “\” for escaping is hellishly inconvenient in a current project and propose replacing it with one of «, —, “, ¶, §, or ~. This Friday, I’ll be running some polls tagged #unbackslash to let you all join in.

#software #regex

Unbackslash

ongoing by Tim Bray

@timbray The left guillemet is not hard to type on Mac (or iOS) keyboards: Option-\. It's thus even mnemonically tied to backslash.

But semantically I see « and I want to see a corresponding » (Shift-Option-\). So my spitball idea would be using left and right guillemets to "quote" the escaped special character:

«(»[^«n»«r»)]*«)»

@gruber I have to say that looks nice. Hmm, using a pair of enclosing markers suggest they could contain more than one character… So you could also have «P{Lu}» rather than «P»{Lu}. Not sure how I feel about that.

@timbray I thought of that too, but didn't want to send you down that rabbit hole. But it's intriguing.

The problem I'm thinking about is that sometime you want to escape a literal character: «(» would mean a literal open paren, but «n» would mean a newline. There aren't many non-literal escapes, though. So, another spitball (could be a truly horrible idea?): what if you keep backslash for non-literal escapes like \n and \r, but use «…» to mean “quote these characters literally”?

@timbray So you could type this to get three consecutive literal open parentheses:

«(((»

or

«\\»

to get 2 literal backslashes. Both of those are zillions more legible than `\(\(\(` or the infamous matchsticks of `\\\\`.

@gruber All this is compelling, but my library’s users are developers not civilians, and being able to just say “put an X wherever you used to put a \” is attractive. Also I'm kinda over inventing container syntax. Having said that, your idea is visually attractive.

@timbray Trust me, I totally, 100 percent see the appeal of “put an X wherever you used to put a \”.

But my mind starts turning…