Backreferences to optional expressions


show more Backreferences to optional expressions provides you with in-depth training on Developer. Taught by Kevin Skoglund as part of the Using Regular Expressions show less
please wait ...

Backreferences to optional expressions

In this movie, I want us to take a closer look at a special case where backreferences refer to optional expressions. There are two things here that can really trip you up that I want you to watch out for. First, let's remind ourselves how optional elements work. So let's say that we just have a simple expression that's A, question mark, B. The A is optional, because the question mark is a quantifier that says that A can occur either zero time, or one-time in the expression, and will still have a successful match. So it matches both A, B, and B. Now let's imagine if we put parentheses around the A, and the question mark, then what will get matched if we ran it against both of those strings; against A, B, and B? The answer is that captures do still occur on zero width matches.

Obviously, if we are matching it against A, B, then what it captures is A. But if we are matching it against just B, then it captures nothing; an empty string. Why is that? Because we said, look, it...

Backreferences to optional expressions
Video duration: 3m 51s 5h 36m Intermediate

Viewers:

Backreferences to optional expressions provides you with in-depth training on Developer. Taught by Kevin Skoglund as part of the Using Regular Expressions

Subject:
Developer
Software:
Regular Expressions
Author:
please wait ...