1 of 85

Regular expressions

Justin Myers (@myersjustinc)

2 of 85

3 of 85

[A-Z]\w+

\d{,3}(,\d{3})*

^\[.*?\]

^(IX|IV|V?I{0,3})$

4 of 85

5 of 85

https://xkcd.com/208/

6 of 85

7 of 85

8 of 85

9 of 85

10 of 85

https://github.com/jkeefe/weatherbot

11 of 85

https://www.flickr.com/photos/pasukaru76/3998273279/

12 of 85

capital letter��followed by five lowercase letters

13 of 85

for character in big_long_text:� value = ord(character)� if value >= 65 and value <= 90:� # Capital letter!� match = character� # TODO: Do lowercase letters follow?� else:� continue

14 of 85

15 of 85

16 of 85

17 of 85

18 of 85

19 of 85

http://bit.ly/nicar17-regex

20 of 85

21 of 85

22 of 85

23 of 85

24 of 85

25 of 85

26 of 85

[A-Z]\w+

\d{,3}(,\d{3})*

^\[.*?\]

^(IX|IV|V?I{0,3})$

27 of 85

a

Prepping pies

Google

Peggy Schuyler

Exception

Extremely funny

Baking cakes

Yahoo! (or Altaba)

Alexander Hamilton

Regular expression

Half-witted

Does match:

Does not match:

28 of 85

ac

Macaroni

Self-actualization

MacGyver

Back-to-back

Galactica

Spaghetti

Safety

Tony Stark

Looking forward

Pegasus

Does match:

Does not match:

29 of 85

30 of 85

31 of 85

32 of 85

33 of 85

34 of 85

35 of 85

36 of 85

37 of 85

38 of 85

39 of 85

40 of 85

41 of 85

42 of 85

43 of 85

k

.

44 of 85

45 of 85

46 of 85

47 of 85

48 of 85

49 of 85

50 of 85

51 of 85

52 of 85

53 of 85

54 of 85

55 of 85

https://www.flickr.com/photos/fdecomite/8443261903/

56 of 85

57 of 85

58 of 85

59 of 85

60 of 85

61 of 85

62 of 85

63 of 85

64 of 85

65 of 85

66 of 85

^

$

67 of 85

68 of 85

69 of 85

70 of 85

71 of 85

72 of 85

73 of 85

74 of 85

75 of 85

\1

\2

76 of 85

\1

\2

77 of 85

78 of 85

79 of 85

80 of 85

81 of 85

\1

\2

\3

82 of 85

83 of 85

84 of 85

85 of 85

What now?

  • More advanced things
  • Just mess around
  • Leave