Ruby is a direct descendant of Perl and borrows its regex syntax.
Re:Perl 5.26.0 released
by MadcapJake on Thursday June 01, 2017 @11:08AM
(#14460861)
Ruby used Oniguruma (and now Onigmo) for RegEx https://github.com/k-takata/Onigmo
Re:Perl 5.26.0 released
by dragonwriter on Thursday June 01, 2017 @12:41PM
(#14461884)
Yes (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.
As far as I can make out these regex engines are very close to Perl5.
Javascript has regex literals
/foo\sbar/i;
Is the same as: new RegExp('foo\\sbar', 'i');One 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+")Some other languages have a "raw string" syntax which disables backslash processing. For instance, Python (see https://docs.python.org/3/library/re.html and https://docs.python.org/3/reference/lexical_analysis.html#st...) and Rust (see https://doc.rust-lang.org/reference/tokens.html#raw-string-l...).
Re:Perl 5.26.0 released
by dragonwriter on Thursday June 01, 2017 @12:39PM
(#14461867)
> Perl is still the only language I've seen that has a dedicated syntax for regular expressions.
So, you've never seen Ruby?
Re:Perl 5.26.0 released
by rcthompson on Saturday June 03, 2017 @10:16AM
(#14476473)
I've done a very small about of ruby programming which did not involve regular expressions.
(I'm sure there must be other languages with dedicated regex syntax, but I'm not aware of any.)