APCS: Regular Expressions

 

Regular Expressions are about pattern matching. Any popular computer language includes the ability to handle regular expressions (regex). In a regex, you define a pattern. You can then 'throw' a lot of input (words, numbers, characters, etc.) at the pattern, and the regex will tell you which parts of the input match the pattern. A simple example is exercise #1, in which you search the play Romeo and Juliet for the surnames "Montague" and "Capulet." You define the regex to search for these words.

 

Try out these exercises to get a feeling for what a regular expression can do. You don't have to do all of them (and you probably won't have time to do all of them.)

1. Literal Strings

2. Character Classes

3. Extract A Poem

4. Beginning and Ending Characters

5. Credit Cards

6. Email

7. LookBehind

8. LookAhead

 

 


AP Computer Science