Crosswords Help You Learn Regular Expressions

Regular expressions might seem arcane, but if you do any kind of software, they are a powerful hacker tool. Obviously, if you are writing software or using tools like grep, awk, sed, Perl, or just about any programming language, regular expressions can simplify many tasks. Even if you don’t need them directly, regular expression searches can help you analyze source code, search through net lists, or even analyze data captured from sensors.

If you’ve been using regular expressions for a long time, they aren’t very hard. But learning them for the first time can be tedious. Unless you try your hand at regular expression crosswords. The clues are regular expressions and the rows and columns all have to match the corresponding regular expressions.

For example, consider this puzzle (which is already filled out):

crossex

This puzzle has a theme (The Beatles). The first across clue says that the two characters have to be an HE or an LL or one or more Os (two, then, in this case). The first down clue says the characters can’t be S, P, E, A, or K. So even though the second across clue says the lower left cell could be an A (in PLEASE), that would violate the down clue.

Of course, this is a super simple puzzle, but the site has many more puzzles of increasing difficulty. If you prefer your puzzles in hardware, that’s ok. If you want to work a different kind of puzzle, you might look at our Omnibus.

18 thoughts on “Crosswords Help You Learn Regular Expressions

  1. Yep. Regex – lead balloons, they have a lot in common.

    Here’s the REGEX rules –
    1) Avoid Regex at all costs
    2) Tell people you know all about regex when you don’t
    3) Then you have to do that server side MOD_REWRITE, google it – someone else is sure to have done it before – then don’t tell anyone.
    4) Now you’ve mastered regex

      1. #1 is because 1 *have* learnt regex! Try to use Apache MOD_REWRITE without regex!!!

        It’s a pain to write efficient parsers (apart from MOD_REWRITE) and even then regex always comes with a significant performance cost.

        If you need to do something with regex then someone has probably done it before and they have probably made it as efficient as it can be so google it! and save yourself a lot of time.

        There are almost always alternatives to regex and they are almost always more efficient. In rare occasions you actually need regex.

        And then there is that readability issue that makes it the worst code in the world!!!!

        So tell me what very simple function this regex does …

        /^(?!(?:(?:\x22?\x5C[\x00-\x7E]\x22?)|(?:\x22?[^\x5C\x22]\x22?)){255,})(?!(?:(?:\x22?\x5C[\x00-\x7E]\x22?)|(?:\x22?[^\x5C\x22]\x22?)){65,}@)(?:(?:[\x21\x23-\x27\x2A\x2B\x2D\x2F-\x39\x3D\x3F\x5E-\x7E]+)|(?:\x22(?:[\x01-\x08\x0B\x0C\x0E-\x1F\x21\x23-\x5B\x5D-\x7F]|(?:\x5C[\x00-\x7F]))*\x22))(?:\.(?:(?:[\x21\x23-\x27\x2A\x2B\x2D\x2F-\x39\x3D\x3F\x5E-\x7E]+)|(?:\x22(?:[\x01-\x08\x0B\x0C\x0E-\x1F\x21\x23-\x5B\x5D-\x7F]|(?:\x5C[\x00-\x7F]))*\x22)))*@(?:(?:(?!.*[^.]{64,})(?:(?:(?:xn--)?[a-z0-9]+(?:-[a-z0-9]+)*\.){1,126}){1,}(?:(?:[a-z][a-z0-9]*)|(?:(?:xn--)[a-z0-9]+))(?:-[a-z0-9]+)*)|(?:\[(?:(?:IPv6:(?:(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){7})|(?:(?!(?:.*[a-f0-9][:\]]){7,})(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,5})?::(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,5})?)))|(?:(?:IPv6:(?:(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){5}:)|(?:(?!(?:.*[a-f0-9]:){5,})(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,3})?::(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,3}:)?)))?(?:(?:25[0-5])|(?:2[0-4][0-9])|(?:1[0-9]{2})|(?:[1-9]?[0-9]))(?:\.(?:(?:25[0-5])|(?:2[0-4][0-9])|(?:1[0-9]{2})|(?:[1-9]?[0-9]))){3}))\]))$/iD

  2. I think the real challenge and art to Regex is crafting them in such a way as to make your intentions clear to yourself and to others, especially after months or years have passed. If one is capable of doing this then I suspect they will instantly vanish in a flash of enlightenment and become an energy being of unlimited power.

Leave a Reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.