[PSA] generative AI: a cure for your regex woes?

26 views
Skip to first unread message

Flynn, Ted@DWR

unread,
May 10, 2023, 6:14:24 PM5/10/23
to Bay-Delta Data Science Fun

Hey all,

Just wanted to share my great success using generative AI (ChatGPT in this case) to conquer a thorny foe: regular expressions. I wanted to pull three-letter station names out of a string like “DRIFT_ANH_2019_01_25” using stringR and couldn’t come up with a regex pattern using my limited knowledge of the subject.

 

Enter our new AI overlords. Soon my timid query of “write a regular expression to return the characters after the string ‘DRIFT_’ and before ‘_’” was turned into (?<=DRIFT_)[^_]+ faster than you can say “gee I hope we all still have jobs in 5 years.”

 

Hope this helps!

 

- Ted

---
Ted Flynn, PhD
Senior Environmental Scientist (Supervisor)
theodor...@water.ca.gov
Division of Integrated Science & Engineering
California Department of Water Resources
Call/text @ (916) 820-5052


saveourwater.com

 

Kyle Hardage

unread,
May 10, 2023, 6:44:07 PM5/10/23
to Flynn, Ted@DWR, Bay-Delta Data Science Fun
I had similar success pulling N characters before and after special characters to extract units from a long string of EPA methods. Good stuff.

I did find that ChatGPT added extra brackets to my expression that stringr would not evaluate, so it took some playing around to get the right result. Still a great starting point though!

--
https://interagencyecologicalprogram.github.io/DataScience/
---
You received this message because you are subscribed to the Google Groups "Bay-Delta Data Science Project Work Team" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bay-delta-datasc...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bay-delta-datascience/SJ0PR09MB68466779150DB9B917FD47B0A4779%40SJ0PR09MB6846.namprd09.prod.outlook.com.

Alstad, Karrin@Wildlife

unread,
May 25, 2023, 2:49:11 PM5/25/23
to Kyle Hardage, Flynn, Ted@DWR, Bay-Delta Data Science Fun

RE conversations with ChatGPT:   I have been fighting with a formatting problem when exporting from bookdown:rs4_book to html ,, and asking Chat for feedback in so many different ways; nothing was correct..   I have *finally* just figured out what the problem was…   And now I wonder… do I go back and inform Chat of the solution? 

(I am not going to.. I think we need some time apart)

😉ka

 

From: bay-delta-...@googlegroups.com <bay-delta-...@googlegroups.com> On Behalf Of Kyle Hardage
Sent: Wednesday, May 10, 2023 3:44 PM
To: Flynn, Ted@DWR <Theodor...@water.ca.gov>
Cc: Bay-Delta Data Science Fun <bay-delta-...@googlegroups.com>
Subject: Re: [bay-delta-datascience] [PSA] generative AI: a cure for your regex woes?

 

WARNING: This message is from an external source. Verify the sender and exercise caution when clicking links or opening attachments.

 

Reply all
Reply to author
Forward
0 new messages