That way, you won’t read a boring article in the worst passive way, but you’ll be the acting Hero of the Regular Expression Journey™. To understand how regular expressions work, we’ll use, throughout this article, this example file you can download and open in Vim (or copy-paste if you want). If you like my articles about Vim, I’m currently writing an ambitious book about The Best Editor™ with many more tips! What are the common metacharacters we can use in our regexes?.What are the most common regex engines (also called “regex flavors”) available?.What are metacharacters? Why are they different from the characters we all know and love?.In this article, we’ll try to answer these questions: To write regexes, we need tools supporting them we’ll use mostly Vim here, but also GNU Grep to see the difference between two (similar) regex flavors. That’s what we’ll focus on in this article: writing regular expressions for different one-off tasks. You need to find a specific entry in a gigantic pile of logs? You need to replace a specific HTML attribute with another one, whatever its value? Regexes can help you! That said, we don’t have to write regexes in a codebase we can also use them for one-off tasks. Also, their conciseness can make them difficult to parse with our poor brain. Like any bunch of code, they will change overtime, and eventually get more and more complex. It’s true that writing regular expressions (also called “regex” or “regexp”) in a codebase can be problematic. Even if you don’t like the tone of your colleague, you ask yourself: are regular expressions that bad? Should we use them? That was Dave, your colleague developer, patronizing you for using a simple regex to parse an HTML file. They can spiral in a wormhole of quantum complexity. They are difficult to learn, understand, and maintain. “We should never write regular expressions.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |