News for hackers. Stuff that matters.
Re:Show HN: Regex Cheatsheet by crispyambulance on Friday January 31, 2020 @08:57AM (#22201655)
I use regex a lot but deliberately keep it simple.

One thing that confounded me often was positive and negative look-arounds. I always got the expressions mixed up, until I just put the expressions into a table like this...

              look-behind  |  look-ahead
    ------------------------------------
    positive    (?<=a)b    |    a(?=b)
    ------------------------------------
    negative    (?<!a)b    |    a(?!b)

It's not hard, but for whatever reason my brain had trouble remembering the usage because every time I looked it up, each of those expressions was nested in a paragraph of explanation, and I could not see the simple intuitive pattern.

Putting it into a simple visualization helps a lot.

Now, if I can find a similar mnemonic for backreferences !?

Re:Show HN: Regex Cheatsheet by wahern on Friday January 31, 2020 @10:36AM (#22202491)
Maybe it's easier to remember that lookbehinds are evil from an implementation standpoint, and even in Perl have arbitrary limitations. If you see lookbehinds, look away! If you see lookaheads, go ahead.
Re:Show HN: Regex Cheatsheet by glangdale on Friday January 31, 2020 @05:57PM (#22206814)
Oddly, lookbehinds are evil only in a specific backtracking world. We never got around to implementing arbitrary lookarounds in Hyperscan (https://github.com/intel/hyperscan) but if we had done something in the automata world to handle lookaround, lookbehinds are way easier than lookaheads.

To handle a lookbehind, you really only need to occasionally 'AND' together some states (not an operation you would normally do in a standard NFA whether Glushkov or Thompson). To handle lookaheads... well, it gets ugly.

Re:Show HN: Regex Cheatsheet by wahern on Friday January 31, 2020 @07:35PM (#22207519)
Even for non-fixed length expressions?
Re:Show HN: Regex Cheatsheet by glangdale on Tuesday February 04, 2020 @12:11AM (#22232616)
Variable-length backward asserts are fine in automata-land, which is a bit peculiar.
Re:Show HN: Regex Cheatsheet by ygra on Friday January 31, 2020 @12:40PM (#22203637)
It's something I really like about .NET's regular expressions. Lookbehind has no limitations and will just match backwards with all features you can use in other parts.

So depending on the language or flavor you're working in, running away isn't really necessary.

Re:Show HN: Regex Cheatsheet by lonelappde on Friday January 31, 2020 @05:56PM (#22206800)
Lookbehinds stay behind.
Re:Show HN: Regex Cheatsheet by geongeorgek on Friday January 31, 2020 @09:11AM (#22201759)
This is really intended for beginners. but I can confirm more content is coming soon <3