Regular Expressions cheat sheet

Regular expression is a powerful tool, and it can save lots of lines codes sometimes. What… » DEV Community | dev.to

3 de diciembre de 2020 · 1 min · 21 palabras · Nacho Cano

Intro to Bash Regular Expressions

To me, regular expressions are often made far more complicated than they need to be. Sure, there… » DEV Community | dev.to

19 de octubre de 2020 · 1 min · 22 palabras · Nacho Cano

Regex para torpes

Regex para torpes » blog.adrianistan.eu | blog.adrianistan.eu

27 de julio de 2020 · 1 min · 7 palabras · Nacho Cano

Demystifying the regular expression that checks if a number is prime

A while back I was researching the most efficient way to check if a number is prime. This lead me to find the following piece of code: public static boolean isPrime(int n) { return !new String(new char[n]).matches(”.?|(..+?)\\1+”); } I was intrigued. While this might not be the most efficient way, it’s certainly one of the less obvious ones, so my curiosity kicked in. How on Earth could a match for the .?|(..+?)\1+ regular expression tell that a number is not prime (once it’s converted to its unary representation)? ...

10 de septiembre de 2016 · 1 min · 92 palabras · Nacho Cano

Visualization of Regular Expression Character Classes

We all know the regular expression character classes, right? There are 12 standard classes: [:alnum:] [:digit:] [:punct:] [:alpha:] [:graph:] [:space:] [:blank:] [:lower:] [:upper:] [:cntrl:] [:print:] [:xdigit:] But have you seen a visual representation of what these classes match? Probably not. Therefore I created a visualization that illustrates which part of the ASCII set each character class matches. » Peteris Krumins | catonmat.net

26 de marzo de 2013 · 1 min · 62 palabras · Nacho Cano

Regular Expression Matching Can Be Simple And Fast

Historically, regular expressions are one of computer science’s shining examples of how using good theory leads to good programs. They were originally developed by theorists as a simple computational model, but Ken Thompson introduced them to programmers in his implementation of the text editor QED for CTSS. Dennis Ritchie followed suit in his own implementation of QED, for GE-TSS. Thompson and Ritchie would go on to create Unix, and they brought regular expressions with them. By the late 1970s, regular expressions were a key feature of the Unix landscape, in tools such as ed, sed, grep, egrep, awk, and lex. Today, regular expressions have also become a shining example of how ignoring good theory leads to bad programs. The regular expression implementations used by today’s popular tools are significantly slower than the ones used in many of those thirty-year-old Unix tools. This article reviews the good theory: regular expressions, finite automata, and a regular expression search algorithm invented by Ken Thompson in the mid-1960s. It also puts the theory into practice, describing a simple implementation of Thompson’s algorithm. That implementation, less than 400 lines of C, is the one that went head to head with Perl above. It outperforms the more complex real-world implementations used by Perl, Python, PCRE, and others. The article concludes with a discussion of how theory might yet be converted into practice in the real-world implementations. ...

21 de junio de 2012 · 2 min · 235 palabras · Nacho Cano