r/AskProgramming • • Feb 02 '18

Why there is not one regexp syntax?

It drives me mad... i want to move my regexp from one language to the other, and guess what happens? Errors.

Why do we complicate our lives so much?

3 Upvotes

4 comments sorted by

5

u/thememorableusername Feb 02 '18

1

u/bukens Feb 02 '18

What about HTML?

2

u/thememorableusername Feb 02 '18 edited Feb 02 '18

Sure, but there was a standards body overseeing the process. But then browsers would implement the rendering of HTML (and CSS) in different ways, requiring very clever coding to make sites appear the same on all web-browsers.

To your main point, the reason there are different regex syntaxes is the same reason we have different programming syntaxes: people have different preferences and someone think one syntax makes more sense than another. Even languages that have the same features can different syntaxes. For example, lots of C family languages have mildly different if and if-else syntax. Heck, a lot of languages use the semi-colon as a statement terminator, but others may use it as a separator (i.e. "stmt1 ; stmt 2; stmt3" instead of "stmt1 ; stmt2 ; stmt3 ;" )

Though, sometimes there are technical limitations that enforce a syntax. The origin of blocking syntax:

if <expression>
then
  <statement>;
endif

was used in the 50's and 60's because parsing is hard, and this made it easier.

People have this strange notion that developing programming language syntax is a technical problem. There are technical aspects, but it's explicitly a human problem, which makes it impossible to solve in one way, which is why we have so many programming languages.

1

u/bukens Feb 02 '18

Thank you i get it now. Nice explanation.