Live data from Hacker News

The true power of regular expressions (2012)

npopov.com

41–50 of 62 posts

Re: The true power of regular expressions (2012)

#41

This article misleads you by conflating regular expressions with specific implementations like PCRE, which also does non-regex string matches. Annoyingly, the article does a good job of explaining what a regex is and what the limitations of regex are relative to PCRE, so the author should understand that what they are talking about when they talk about NP-complete string matching is not regex, but PCRE-specific featu…

Actually TFA is explicit about this:

> Regular expressions in the formal grammar sense can (pretty much by definition) only parse regular grammars and nothing more.

> But when programmers talk about “regular expressions” they aren’t talking about formal grammars. They are talking about the regular expression derivative which their language implements. And those regex implementations are only very slightly related to the original notion of regularity.

> Any modern regex flavor can match a lot more than just regular languages. How much exactly, that’s what the rest of the article is about.

Re: The true power of regular expressions (2012)

#42

This article misleads you by conflating regular expressions with specific implementations like PCRE, which also does non-regex string matches. Annoyingly, the article does a good job of explaining what a regex is and what the limitations of regex are relative to PCRE, so the author should understand that what they are talking about when they talk about NP-complete string matching is not regex, but PCRE-specific featu…

You’re splitting hairs. The author is writing from the perspective of a PHP programmer (author is in fact a major PHP contributor), where the term “regex” has a single very clear definition, namely PHP’s PCRE-based implementation.

Re: The true power of regular expressions (2012)

#43
post #27

Earlier quoted context omitted.

there is, I think, a divide between programmers that is pretty basic. Do they need a language that maps somewhat to written human language, or can they adapt to languages that do do not at all resemble the human languages they are familiar with. This divide is most probably cultural, programmers in Western societies often have pre-programming familiarity with English and thus they do not need to learn a language that…

> as might be the case with programmers from Asian countries or others where familiarity with English is not guaranteed Lots of Asian countries where familiarity with English is assumed in professional contexts. > So if your primary gateway to programming languages are ones that slightly resemble a human language you are familiar with you may have lots of psychological blocks keeping you from making that final jump t…

the might at beginning of the clause was also meant to take into account that people might have familiarity with English, as I could not be certain, but probably should have been expressed better.

Re: The true power of regular expressions (2012)

#44
post #27

Earlier quoted context omitted.

there is, I think, a divide between programmers that is pretty basic. Do they need a language that maps somewhat to written human language, or can they adapt to languages that do do not at all resemble the human languages they are familiar with. This divide is most probably cultural, programmers in Western societies often have pre-programming familiarity with English and thus they do not need to learn a language that…

> as might be the case with programmers from Asian countries or others where familiarity with English is not guaranteed Lots of Asian countries where familiarity with English is assumed in professional contexts. > So if your primary gateway to programming languages are ones that slightly resemble a human language you are familiar with you may have lots of psychological blocks keeping you from making that final jump t…

I doubt there has been studies on it, but I figure if you are already learning an alphabet and expression in that alphabet that are nonsensical to you to be able to program, then J or APL syntax should be definition not increase difficulty.

Re: The true power of regular expressions (2012)

#46
post #27

Earlier quoted context omitted.

> as might be the case with programmers from Asian countries or others where familiarity with English is not guaranteed Lots of Asian countries where familiarity with English is assumed in professional contexts. > So if your primary gateway to programming languages are ones that slightly resemble a human language you are familiar with you may have lots of psychological blocks keeping you from making that final jump t…

I doubt there has been studies on it, but I figure if you are already learning an alphabet and expression in that alphabet that are nonsensical to you to be able to program, then J or APL syntax should be definition not increase difficulty.

It might show up if there are national or even regional numbers for popular languages.

Re: The true power of regular expressions (2012)

#47
post #27

Earlier quoted context omitted.

> as might be the case with programmers from Asian countries or others where familiarity with English is not guaranteed Lots of Asian countries where familiarity with English is assumed in professional contexts. > So if your primary gateway to programming languages are ones that slightly resemble a human language you are familiar with you may have lots of psychological blocks keeping you from making that final jump t…

the might at beginning of the clause was also meant to take into account that people might have familiarity with English, as I could not be certain, but probably should have been expressed better.

I should really have worded my comment differently too. You need to filter out those Asian countries.

Thinking about it, I think one thing that might stop that is that most people will start with English like languages first even if they are not English speaking and by the time they learn things like APL they will already be familiar with the more common style of languages.

Re: The true power of regular expressions (2012)

#48

It might just be a me problem, but I've always been wary of regexes. They're not too bad to write, but reading them back and understanding what's actually going on can get a bit hairy. Plus, all of the subtle differences between regex libraries seems like a bit of a footgun. Obviously they have their place, but I know a lot of the older guys seemed to love them way more than the young.

The readability should be compared to alternative ways to solve the same problem. Sure, regexes are not the most intuitive syntax, but it is compact and declarative. What is the alternative? Substring searches? Looping over characters? Hand-rolled recursive descent? Neither are obviously more readable, and intermingles the pattern with the mechanism.

Re: The true power of regular expressions (2012)

#49
post #9

Earlier quoted context omitted.

I'm wary of external urls in code. Some plaintext comment would come in handy for the day the link inevitably goes dead.

Why could external URLs be a problem? And is it still one if you swap https to hxxps or something? What could go wrong with having a URL as a comment in code? I put URLs there sometimes and think it's very helpful.

You don't control these external resources, and now the explanation of what your code does is tied to a site that could be taken down tomorrow, leaving you with a dead link and an unexplainable regex.

Re: The true power of regular expressions (2012)

#50

This article misleads you by conflating regular expressions with specific implementations like PCRE, which also does non-regex string matches. Annoyingly, the article does a good job of explaining what a regex is and what the limitations of regex are relative to PCRE, so the author should understand that what they are talking about when they talk about NP-complete string matching is not regex, but PCRE-specific featu…

You’re splitting hairs. The author is writing from the perspective of a PHP programmer (author is in fact a major PHP contributor), where the term “regex” has a single very clear definition, namely PHP’s PCRE-based implementation.

No, this is not splitting hairs. This is the author using the straight up wrong terminology. Regex can’t match HTML, and aren’t NP-complete. The fact that the author believes that “regex obviously means PCRE” is objectively wrong and misleading in the sense that all the things his article are about would have another conclusion if he actually talked about Regex.

It’s like if there was a library called QuickSort which also included a SAT solver and I then wrote an article about how you can solve SAT-equivalent problems with quicksort (“in the programmer sense, which obviously means a SAT solver”)

Post reply on HN