![]() (? … ) must be a lookahead, right? Not so. (?: … ) contains a non-capturing group, while (?= … ) is a lookahead. These false twins have very different jobs. ✽ Pre-Defined Subroutines: (?(DEFINE)( … )( … )) and (?&foo)Ĭonfusing Couples Confusing Couple #1: (?: … ) and (?= … ) I'll start by pointing out three confusing couples details of usage will follow.įor easy navigation, here are some jumping points to various sections of the page: ![]() To facilitate study, I have pulled all the (? … ) usages I know about into one place. But (?: … ) looks a lot like (?= … ), so that at some point they are bound to clash in the mind of the regex apprentice. In the regex tutorials and books I have read, these various points of syntax are introduced in stages. ![]() One of the things that make regexes hard to read for beginners is that many points of syntax that serve vastly different purposes all start with the same two characters: The heroes who expanded regular expressions (such as Henry Spencer and Larry Wall) followed in these footsteps. Maybe they were into hieroglyphs, maybe they were into cryptography, or maybe that was just the way you did things when you only had a few kilobytes or RAM. Stephen Kleene and Ken Thompson, who started them, obviously wanted something very compact. I don't know the fine details of the history of regular expressions. I thought I would bring them all together in one place. ![]() A question mark inside a parenthesis: So many uses! ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |