RegEx Quantifiers


Quantifiers are how regex handles repitition i.e. how many to match.

CREATED 2016-04-19 14:34:10.0

00-24-D3

UPDATED 2016-04-19 14:34:30.0

The Question Mark (?) - Optional (zero to one)


Qustion mark is a quantifier that searches for zero or none of the preceeding i.e. question makes what precedes it optional.

Example: Kenn?y? or Ken(ny)? would return all lines with either Ken or Kenny in them. The second n and y are followed by question mark which makes them optional. When using parenthesis everything inside them would be optional as parenthesis are used for grouping.

July? would match on all lines that contained either Jul or July because the y is optional so it isn't needed to make a match.

However, the question mark (?) also moonlights as a modifier where it appears in the begining or middle of a statement.

Example "(?i)Some"

This would make the match case insensitive and therefore would match Some, sOme, soMe, somE, etc

And "So(?i)me" would match Some, SoMe, SomE, SoME but not SOME or sOme, etc.

CREATED 2016-04-24 13:05:57.0

00-24-DB

UPDATED 2016-04-25 12:28:40.0

The Plus (+) - one to many


Plus extends an expression one or more times. For example: ^[A-Z] would match all lines that begin with a capitol letter, ^[A-Z]+ would match all lines that begin with one or more capitol letters.

Unlike other quantifiers, plus must match at least once.

CREATED 2016-04-19 14:35:31.0

00-24-D5

UPDATED 2016-04-25 12:28:47.0

The Astrisk (*) - zero to many


Sometimes refered to as star. The Astrisk extends an expression zero or more times. Astrisk will match zero or more times i.e. astrisk doesn't have to make a match to be sucessful.

CREATED 2016-04-23 12:02:53.0

00-24-DA

UPDATED 2016-04-25 12:28:15.0

Roll Your Own (x,y)


In some flavors you can roll your own quantifiers. Enclosed in parenthesis, give the engine the match to start on and how long to match. For example Hello(3,6) will start to match on the third occurance of H-e-l-l-o and stop matching on the sixth occurance.

CREATED 2016-04-27 14:28:08.0

00-24-DC

UPDATED 2016-04-27 14:28:45.0

L
I
N
K
S

DBID: db.wam

Page Server: Ruger

©2019 Leistware.com
        Hello anonymous