Navigating the Large Language Model choices_Ravi Daparthi
Regex Primer
1. (?<=REGEX)
PRIMER
D A L L A S H A C K E R S A S S O C I AT I O N
C H R I S M E R C E R – D H A @ Z A I M O R . C O M
2. DISCLAIMER
• IANARE: I am not a RegEx expert
• This is a crash course in what RegEx
is and what it can do
• Hopefully this will teach you some
new tricks to make your text
transforming bearable
3. DID YOU KNOW…
• Raise your hand if you’ve heard of RegEx!
• Put them DOWN if you DIDN’T know you could use RegEx to:
– Validate input (make sure someone put in a correctly formed email)
– Find text in code, in commands, and in text apps like vim, atom,
notepad++
– Find matches before or after other text (like finding a q without a u)
– Find text based on conditions (find A followed by T if it starts with C,
otherwise followed by S)
– Find AND REPLACE variable pieces of text (replace full names with
initials)
• If your hand is still up, go pick locks. You’re not learning anything
from me today. For the rest of you…
4. WTF IS REGEX?
• RegEx, or Regular Expressions, is a defined
“pattern” used for finding a specific string of text
• Wildcards on steroids
• You can find text that:
– Is before or after other text
– Is made up of a set of characters
– Is grouped together/saved to reference later
– Includes of tabs, spaces, new lines, special characters
• Several flavors/implementations, all “mostly”
compatible
5. VALIDATE/SEARCH
• Easiest, most well-known way to use RegEx
• Find a variable string of text, or validate that user input matches a required format
7. FIND TEXT IN PROXIMITY
• Lookahead (Positive or Negative)
– Find “bob” but only before “saget”
– Find “bob” but NOT before “saget”
• Lookbehind (Positive or Negative)
– Find “saget” but only after “bob”
– Find “saget” but NOT after “bob”
9. REPLACE
^([A-Z])(?:[a-z])*(?:s(?:([A-Z])(?:[a-z])*))?s(?:([A-Z])(?:[a-z])*)$
• Find (F)irst (optional (M)iddle) (L)ast, save initials to $1, $2, $3
– James Bond
– Rory Gilmore
– Johnny Appleseed
– George W Bush
– Jimmy Jo Bob
• Replace with “First: $1 Middle: $2 Last: $3":
– First: J Middle: Last: B
– First: R Middle: Last: G
– First: J Middle: Last: A
– First: G Middle: W Last: B
– First: J Middle: J Last: B
10. HOW DOES THIS HELP AVERAGE JOE?
What if…
I’m a teacher, and I want to take an old exam with 100 questions that looked like this:
1. Question
Answer 1
Answer 2
Answer 3
Answer 4
And format it for importing to another system like this:
Question 1|Question|A. Answer 1|B. Answer 2|C. Answer 3|D. Answer 4
Question 2|Question|A. Answer 1|B. Answer 2|C. Answer 3|D. Answer 4