Oh dear. No JavaScript? You'll be reading an outline, then. Which is fine, really.

Regular Expressions

CUNY logo

Amanda Hickman

CUNY Graduate School of Journalism

CUNY logo

@amandabee

@cunyjschool

XKCD on Regex

[abc]

A single character of: a, b, or c

 

^

Start of line

[^abc]

Any single character except: a, b, or c

 

$

End of line

[a-z]

Any single character in the range a-z

 

\A

Start of string

[a-zA-Z]

Any single char in the range a-z or A-Z

 

\z

End of string

(...)

Capture everything enclosed

 

.

Any single character

(a|b)

a or b

 

\s

Any whitespace character

a?

Zero or one of a (lazy)

 

\S

Any non-whitespace character

a*

Zero or more of a (greedy)

 

\d

Any digit

a+

One or more of a

 

\D

Any non-digit

a{3}

Exactly 3 of a

 

\w

Any word character (letter, number, underscore)

a{3,}

3 or more of a

 

\W

Any non-word character

a{3,6}

Between 3 and 6 of a

 

\b

Any word boundary

options: i case insensitive; m make dot match newlines; x ignore whitespace in regex; o perform #{...} substitutions only once

Strings just means a bunch of characters strung together; Characters are just letters and numbers and curly braces and plus signs.

James, Jim, Jimmy ...

Jim[my] {0,2}
Jimy, Jimm, Jimmm, Jimym
NAME: Sean Burnett POS: RP AGE: 30 WT: 200 BORN: Dunedin, FL SALARY: 2350000
NAME: Tyler Clippard POS: RP AGE: 27 WT: 200 BORN: Lexington, KY SALARY: 1650000
NAME: Ross Detwiler-Smith POS: SP AGE: 26 WT: 174 BORN: St. Louis, MO SALARY: 485000
NAME: Christian Garcia POS: RP AGE: 27 WT: 215 BORN: Miami, FL SALARY: N/A
NAME: Gio Gonzalez POS: SP AGE: 27 WT: 205 BORN: Hialeah, FL SALARY: 3335000
NAME: Mike Gonzalez POS: RP AGE: 34 WT: 215 BORN: Robstown, TX SALARY: N/A
NAME: Ryan P. Mattheus POS: RP AGE: 28 WT: 215 BORN: Sacramento, CA SALARY: 481000
NAME: Craig Stammen POS: RP AGE: 28 WT: 200 BORN: Coldwater, OH SALARY: 485000
NAME: Drew Storen POS: RP AGE: 25 WT: 180 BORN: Indianapolis, IN SALARY: 498750
NAME: Jordan Q. Zimmermann POS: SP AGE: 26 WT: 218 BORN: Auburndale, WI SALARY: 2300000
Sean Burnett, RP, 30, 200, Dunedin, FL, 2350000
Tyler Clippard, RP, 27, 200, Lexington, KY, 1650000
Ross Detwiler-Smith, SP, 26, 174, St. Louis, MO, 485000
Christian Garcia, RP, 27, 215, Miami, FL, N/A
Gio Gonzalez, SP, 27, 205, Hialeah, FL, 3335000
Mike Gonzalez, RP, 34, 215, Robstown, TX, N/A
Ryan P. Mattheus, RP, 28, 215, Sacramento, CA, 481000
Craig Stammen, RP, 28, 200, Coldwater, OH, 485000
Drew Storen, RP, 25, 180, Indianapolis, IN, 498750
Jordan Q. Zimmermann, SP, 26, 218, Auburndale, WI, 2300000

Rubular and RegEx 101

NAME: Sean Burnett POS: RP AGE: ...
NAME: Tyler Clippard POS: RP AG ...

 

NAME: \w* \w* NAME: [-\w ]*
310-808-5243
(415) 846-1688
(720) 318-9049
323.888.6200
323-888-6237
3238886209
323/888.6202
3237078576
3232162201
(323) 960-3100
727-455-4538
727-214-5862
7274555955
4242090017
(646) 879-9137
3239533396
323-816-9613
323/816.7010

Rubular and RegEx 101

XKCD on Regex

Use the spacebar or arrow keys to navigate