Learn Java Programming - Regex Backreference Tutorial

Publié le: 16 février 2016
sur la chaîne: Daniel Ross
1,983
26

What is a regex backreference? Backreferencing is all about repeating characters or substrings. There are occasions where you may want to isolate repeated substrings or characters within your search string. Backreferences work in conjunction with capturing groups to perform subsequent pattern matches. You will match the first occurrence of your regex with a capturing group, and then you can use backreferences to automatically locate subsequent matches. There are two types of backreferences, numbered backreferences and named backreferences.
I'll start off with a simple example, consider my grocery list: "Apples, bananas, and tootsie rolls."
What are the characters that repeat in my grocery list? "Apples, bananas, and tootsie rolls."
We can write a regex to find these repeating characters like this: "(a)\\1", or "(o)\\1", or "(l)\\1". We can also simplify the regex by using the \\w metacharacter - "(\\w)\\1".


Sur cette page du site, vous pouvez voir la vidéo en ligne Learn Java Programming - Regex Backreference Tutorial durée heure minute seconde en bonne qualité , qui a été Téléchargé par l'utilisateur Daniel Ross 16 février 2016, Partagez le lien avec vos amis et connaissances, sur youtube cette vidéo a déjà été regardée 1,983 fois et il a aimé 26 téléspectateurs. Bon visionnage!