Presentation is loading. Please wait.

Presentation is loading. Please wait.

How to cheat at Scrabble An intro to regular expressions

Similar presentations


Presentation on theme: "How to cheat at Scrabble An intro to regular expressions"— Presentation transcript:

1 How to cheat at Scrabble An intro to regular expressions

2 Who is Brian Rawlings? Data Architect @ Intermountain Healthcare
Database professional since 1994 B.S. degree in Computer Science NOT an Oracle employee NOT selling anything twitter.com/BrianRawlings

3 Pattern Matching Scrabble is played by forming letter tiles into patterns Data can be like scrabble tiles Regular expressions are used to match patterns Learning to cheat at Scrabble can help you query data

4 Dictionary Table CREATE TABLE TRAIN.WORD_LIST ( WORD VARCHAR2(50 BYTE) ); Table populated with a dictionary from the internet. Various sets are available.

5 Concept: REGEXP Functions
LIKE Very simple pattern matching REGEXP_LIKE Does a pattern exist REGEXP_COUNT How many times does a pattern exist Other Functions REGEXP_REPLACE – Search and Replace REGEXP_SUBSTR – Returns a substring REGEXP_INSTR – Returns the position

6 Start Simple Use “Like” to find words starting with ‘M’ Like ‘%melt’
SELECT * FROM train.word_list WHERE word like 'M%'; Like ‘%melt’ Like ‘%melt%’

7 Limitations of LIKE I've got four Ts. What words can I make with four Ts? I've got a Q but no U. What words have a Q not followed by a U? What words can I make with these 7 letters?

8 Start of a word Use REGEXP_LIKE to find words starting with ‘M’
SELECT * FROM train.word_list WHERE regexp_like(word, '^M'); ^ represents the start of a word

9 Concept: Anchors Anchors allow you to specify where a match is allowed
^ Beginning of the string $ End of a string

10 End of a word Use REGEXP_LIKE to find words ending with ‘MELT’
SELECT * FROM train.word_list WHERE regexp_like(word,'MELT$'); $ represents the end of a word

11 Concept: Dot What if there is only room for one character?
SELECT * FROM train.word_list WHERE regexp_like (word, '^.MELT$'); ‘.’ represents one character

12 Quiz How many two letter words are in the training dictionary?
How many two letter words start with Q? How many words end with Q? How many four letter words start with “T” end in “R”?

13 Concept: REGEX_COUNT Show words that have at least four Ts? SELECT *
FROM train.word_list WHERE regexp_count(word, 'T') >= 4

14 Concept: Character Class[]
List words ending in a 'q' or a 'u' SELECT * FROM train.word_list WHERE regexp_like(word, '[qu]$');

15 Concept: Repetition List the words can be made with only the letters A and N SELECT * FROM train.word_list WHERE regexp_like(word, '^[AN]+$') The + means repeat this pattern 1 or more times

16 Anagrams How many words can you make from the letters that make up your name? SELECT word FROM train.word_list WHERE regexp_like (word,'^[BRIAN]+$') [] brackets create a set + plus mean set repeat set one or more times

17 Anagrams How many words can you make from the letters that make up your name only once? SELECT word FROM train.word_list WHERE regexp_like(word, '^[BRIAN]+$') AND regexp_count(word, 'B') <= 1 AND regexp_count(word, 'R') <= 1 AND regexp_count(word, 'I') <= 1 AND regexp_count(word, 'A') <= 1 AND regexp_count(word, 'N') <= 1

18 Scrabble Scramble Scrabble equivalent to “Best Ball” in golf
Everyone plays at the same time Use queries to find your best answer 60 seconds between rounds Score your best word. Write down your score on the side of paper Best score will choose next tiles. Compare your best against the group best

19 Questions I created this presentation. You are welcome to use this presentation to train your own team. But if you would like to package it and sell it for millions of dollars, let's talk. Twitter.com/BrianRawlings


Download ppt "How to cheat at Scrabble An intro to regular expressions"

Similar presentations


Ads by Google