Live data from Hacker News

The dangers of single line regular expressions

greg.molnar.io

131–133 of 133 posts

Re: The dangers of single line regular expressions

#131
post #76
post #58

Earlier quoted context omitted.

What if you want to allow users to regex search their documents?

Do it on the client side? Do it in a sandbox and have aggressive timeouts.

> Do it on the client side?

Not practical given a large amount of documents.

> Do it in a sandbox and have aggressive timeouts.

Sure! I was just replying to this:

> the danger of passing anything derived from user input into the TEMPLATE side of a templating engine. Why in the world would you ever do that?!?

Re: The dangers of single line regular expressions

#132
post #56

Raku (perl6) was a chance for Larry Wall to fix some of the limitations of the perl regex syntax, as you would expect from the perl heritage, it behaves similarly. ~ > raku -e 'say "foobar" ~~ /^ +$/ ?? "yes" !! "no"' yes ~ > raku -e 'say "foo\nbar" ~~ /^ +$/ ?? "yes" !! "no"' no ~ > raku -e 'say "foo\nbar" ~~ /^^ +$$/ ?? "yes" !! "no"' yes - ^^ and $$ are the raku flavour of multiline mode - ~~ the smartmatch operat…

Perl has supported whitespace and comments in regular expressions since approximately forever. Just use the /x modifier. All that Raku did was make that flag a default. The same thing is available in many other languages. They copied it when they copied from Perl. For example Python's https://docs.python.org/3/library/re.html#flags documents that re.X, also called re.VERBOSE, does the same exact thing. The fact that…

I was a full time perl coder with plenty of regex back in the day and never appreciated that (sorry) - so maybe making it the default is a good call

PS. raku has added quite a lot to the regex facilities we are familiar with, not least a straight line to using them in Grammars with rule and token methods that give you control over handling of whitespace in the target

Re: The dangers of single line regular expressions

#133
post #56

Raku (perl6) was a chance for Larry Wall to fix some of the limitations of the perl regex syntax, as you would expect from the perl heritage, it behaves similarly. ~ > raku -e 'say "foobar" ~~ /^ +$/ ?? "yes" !! "no"' yes ~ > raku -e 'say "foo\nbar" ~~ /^ +$/ ?? "yes" !! "no"' no ~ > raku -e 'say "foo\nbar" ~~ /^^ +$$/ ?? "yes" !! "no"' yes - ^^ and $$ are the raku flavour of multiline mode - ~~ the smartmatch operat…

Perl has supported whitespace and comments in regular expressions since approximately forever. Just use the /x modifier. All that Raku did was make that flag a default. The same thing is available in many other languages. They copied it when they copied from Perl. For example Python's https://docs.python.org/3/library/re.html#flags documents that re.X, also called re.VERBOSE, does the same exact thing. The fact that…

I think it's fair to say(?) that Larry's adoption of regex as a first class aspect of perl was one of its unique strengths. My opinion is that none of the subsequent languages (Python, Go, Rust, etc) that incorporated regex really embraced it - was more of a bolt on. So there has been a syntactic barrier to incorporate or improve regex within those languages. Not so with Larry's raku which had the vision to build on the perl basis and to address many of the inconsistencies that have been baked in elsewhere.
Post reply on HN