Regex Crossword: Regex Cheat Sheet for All

Regex Crossword: Regex Cheat Sheet for All

The Regex Crossword is the quirky and fun crossword puzzle site for programmers. The crosswords are designed using Regular Expressions (regex) as clues and it’s a great way for designers and programmers to get their head around regex and fine tune their skills. The Regex Crossword site is maintained by Danish developers Maria Hagsten Michelsen and Ole Bjørn Michelsen and is free for anyone to play. What is a regular expression? A regular expression (in summary, regex, or regexp) is a special text string to describe the search pattern. Regular expressions can be considered as special characters in steroids. You may be familiar with wildcards, such as *.txt, to find all text files in the file manager. The equivalent of ^.*\.txt$. But with regular expressions you can do much more. In a text editor like EditPad Pro or a specialized word processing tool like PowerGREP, you can use the regular expression \b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}b to find an email address. Any email address, to be exact. A very similar regular expression (replace the first ^b with ^ and the last one with $) can be used by the programmer to check if the email address is correct. In just one line of code, if the code is written in Perl, PHP, Java, .NET or many other languages. Regular expressions, usually abbreviated to RegEx, are a way of searching the database more generally than usual, used by programmers. For example, you may want to find everyone in your database with the name Stephen or its derivatives. Some of them have a PhD, while others have a degree v and may or may not have a degree s at the end. In RegEx we can look for Ste((ph)|v)ens? Where (a-b) means a or b and s? This line will return all four versions of Stephen as true, but no other word can match the standard. There are many different characters that RegEx uses, but the most common of them are ., which means that any character that produces any of the characters in the range, A* which means any number of A in a line, like YYYYYYYYYYYY, and A+ which is the same, but means that A occurs at least once (so not zero times). All this is very practical if you are working with large data sets, although this XKCD will fall directly on your head: Regex Cheat Sheet – Regex For Any Character This Regex Cheat sheet gives you all the regex for any character you may need. Special credit to RegEgg.com. Where this sheet is summarised from. Characters Character Legend Example Sample Match \d Most engines: one digit from 0 to 9 file_\d\d file_25 \d .NET, Python 3: one Unicode digit in any script file_\d\d file_9੩ \w Most engines: “word character”: ASCII letter, digit or underscore \w-\w\w\w A-b_1 \w .Python 3: “word character”: Unicode letter, ideogram, digit, or underscore \w-\w\w\w 字-ま_۳ \w .NET: “word character”: Unicode letter, ideogram, digit, or connector \w-\w\w\w 字-ま‿۳ \s Most engines: “whitespace character”: space, tab, newline, carriage return, vertical tab a\sb\sc a b c \s .NET, Python 3, JavaScript: “whitespace character”: any Unicode separator a\sb\sc a b c \D One character that is not a digit as defined by your engine’s \d \D\D\D ABC \W One character that is not a word character as defined by your engine’s \w \W\W\W\W\W *-+=) \S One character that is not a whitespace character as defined by your engine’s \s \S\S\S\S Yoyo Quantifiers Quantifier Legend Example Sample Match + One or more Version \w-\w+ Version A-b1_1 {3} Exactly three times \D{3} ABC {2,4} Two to four times \d{2,4} 156 {3,} Three or more times \w{3,} regex_tutorial * Zero or more…

Like to keep reading?

This article first appeared on freshfordesigners.com. If you'd like to keep reading, follow the white rabbit.

View Full Article

Leave a Reply