Live data from Hacker News

Regular expressions that work “everywhere”

johndcook.com

31–40 of 51 posts

Re: Regular expressions that work “everywhere”

#33
We must find a way to return to SNOBOL/PITBOL. It’s so elegant and effective in Ada (where it’s in the standard library).

https://en.wikipedia.org/wiki/SNOBOL

> In the 1980s and 1990s, its use faded as newer languages such as AWK and Perl made string manipulation by means of regular expressions fashionable. SNOBOL4 patterns include a way to express BNF grammars, which are equivalent to context-free grammars and more powerful than regular expressions. The "regular expressions" in current versions of AWK and Perl are in fact extensions of regular expressions in the traditional sense, but regular expressions, unlike SNOBOL4 patterns, are not recursive, which gives a distinct computational advantage to SNOBOL4 patterns.

Re: Regular expressions that work “everywhere”

#34
post #22

Emacs in particular I suffer so much from basically guessing what needs to be escaped or not. I know `rx` exists[0] as an alternative but it's not really fun to use. Even beyond the regex syntax itself, you often also start running into encoding problems when trying to actually use them. Typing the regex in a shell? Make sure to esacpe stuff properly. Regex in Python? Make sure it's a raw string. Etc etc etc It's a m…

Even more fun writing python that generates shell scripts that contain regex, and other nested-different-escaping scenarios.

Re: Regular expressions that work “everywhere”

#38
post #9

The author is circling around, but not quite reaching, a statement that POSIX Basic Regular Expressions work everywhere, with the caveat that that not everyone has caught up with version 8 of the Single Unix Specification, which has slightly changed BREs.

I don't think your comment is fair to the author. If there was not such caveat, then there would not be a need to write that article.

Re: Regular expressions that work “everywhere”

#39
post #9

The author is circling around, but not quite reaching, a statement that POSIX Basic Regular Expressions work everywhere, with the caveat that that not everyone has caught up with version 8 of the Single Unix Specification, which has slightly changed BREs.

I don't think your comment is fair to the author. If there was not such caveat, then there would not be a need to write that article.

[deleted]

Re: Regular expressions that work “everywhere”

#40
post #11

Earlier quoted context omitted.

Why? Of course it means the dialect that is most directly supported by that language (by builtins or the standard library). And why should they have to consider other dialects? They aren't reading regexes from user input (or they'd be a lot more concerned about sanitization, catastrophic backtracking etc.), and their fellow developers all grok the conventions.

Because I don't know what language your program is even written in! Why should I know or care that you chose, e.g. TypeScript, when I'm trying to use or configure your program and don't know how to spell this or that regex concept?

> It drives me nuts when a developer documents something or other as being a "regex"

> I don't know what language your program is even written in!

I legitimately don't understand how you're in this situation. If the documentation is telling you that something is a regex, and it's not a user-supplied regex, then that's something intended for fellow developers. If configuration expects a regex for some reason, that's a signal that you're expected to be a programmer to use the software; and you're presumably interested in it because you use the same language, or are at least familiar enough with the open source ecosystem to look these things up. If the software were meant to be used by people who can't do these things, it would be designed without those rough edges, but more importantly the documentation would be getting written by a non-developer.

Post reply on HN