6 ms·
Perl is still the only language I've seen that has a dedicated syntax for regular expressions. Every other language requires you to write your regexes as string
by rcthompson 9y ago
Perl is still the only language I've seen that has a dedicated syntax for regular expressions. Every other language requires you to write your regexes as strings, which puts you squarely in backslash hell.
(I'm sure there must be other languages with dedicated regex syntax, but I'm not aware of any.)
- ilkkao 9y agoJavascript is like Perl: /foo/i.test('foobar') is valid JS.
- cutler 9y agoRuby is a direct descendant of Perl and borrows its regex syntax.
- MadcapJake 9y agoRuby used Oniguruma (and now Onigmo) for RegEx https://github.com/k-takata/Onigmo https://github.com/k-takata/Onigmo
- cutler 9y agoAs far as I can make out these regex engines are very close to Perl5.
- dragonwriter 9y agoYes (well, for MRI at least; I'm not sure other implemebtations use the same regex engine) and it used a different regex engine before Oniguruma. But engines and syntax are unrelated; Ruby has a dedicated regex literal syntax which was directly inspired by Perl.
- Ardren 9y agoJavascript has regex literals /foo\sbar/i; Is the same as: new RegExp('foo\\sbar', 'i');
- hoytech 9y agoOne thing that annoys me a bit about the JS syntax though: As far as I know, JS regexp literals don't have custom delimiter support. For instance in perl you can do this: $str =~ m{/some/path/\w+} But in JS you need to escape the / characters, or use a normal string as an argument to Regexp, in which case you need to escape the backslashes: /\/some\/path\/\w+/ Regexp("/some/path/\\w+")
- cesarb 9y agoSome other languages have a "raw string" syntax which disables backslash processing. For instance, Python (see https://docs.python.org/3/library/re.html https://docs.python.org/3/library/re.html and https://docs.python.org/3/reference/lexical_analysis.html#string-and-bytes-literals https://docs.python.org/3/reference/lexical_analysis.html#st...) and Rust (see https://doc.rust-lang.org/reference/tokens.html#raw-string-literals https://doc.rust-lang.org/reference/tokens.html#raw-string-l...).
- dragonwriter 9y ago> Perl is still the only language I've seen that has a dedicated syntax for regular expressions. So, you've never seen Ruby?
- rcthompson 9y agoI've done a very small about of ruby programming which did not involve regular expressions.