Previously in this sequence I have mostly spoken about matching exaclty 1 of a character. But what if you want to match something that may or may not be there. For example if you are matching a URL it could start out “http://” or “https://” You can match that with this regex https?:// Where the question mark says take the last pattern and make it match 0 or one times. So it will match the “s” if it is there, but still match if it is not there.

This can also be used with classes, so the regex a\w? will match the letter “a” by itself or with any other letter after it. SO “a”, “ab”, “aa” etc.

If you want to match 0 or more of something use a star “”. So .* will match 0 or more non whitespace characters. Note that the “” Is gready so it will match the longest possible string it can. If you try to match “abbbbbabbbba” with a.*a it will match the entire string not just the first sequence of “b”’s.

If you want to match one or more of something use the plus “+” character.

Ranges: a{3,5} will match the letter a repeated between 3 and 5 times.