this post was submitted on 03 Jul 2023
2 points (56.2% liked)

RegEx

369 readers
1 users here now

Welcome to the RegEx community! This is a place where you can learn about and get help with regular expressions

A regular expression is a sequence of characters that specifies a match pattern in text. Theyre usually used for find, or find and replace operations on strings, or for input validation.


founded 1 year ago
MODERATORS
 

With all the strengths and shortcomings of Chat-GPT, I wanted to share one consistent strength I found it has when working with regex.

  • You can ask it to generate regex patterns for known and custom things.
    • If you are skeptical it is correct (like me), you can ask it to break down the pattern and inspect why the decisions were made. If I don't understand some fields, I type up a quick test and make sure it covers all edge cases.
  • And my personal favorite, you can paste a regex and ask it to tell you what it matches to. No more writing regex and forgetting what they are for!

I don't always have the opportunity to use regex when I work and would shy away from it because it can become illegible, but now that it is so easy I find I am slapping it everywhere and I cutting down on logic when sanitizing inputs/data. The bonus is now that I'm using it more, I am becoming less reliant on having it be generated for me.

top 7 comments
sorted by: hot top controversial new old
[–] nibblebit 3 points 1 year ago (1 children)

Also works for cron jobs, shell scripts, SQL queries, HTML layouts and the odd mermaid diagram

[–] varsock 3 points 1 year ago (1 children)

Yeah totally! I would encourage everyone to try it with their workflow and see where it can make a difference and where it falls short.

Reason I made an example out of regex is b/c of how much hate it gets :D I definitely see why regex is widely appreciated.

[–] nibblebit 4 points 1 year ago (1 children)

Theres like a whole class of "Stuff you have to relearn every time you have to use it": XPath, JMESPath, cron, ffmpeg, ImageMagick, PostScript etc.. REGEX might be king of those :p

[–] varsock 4 points 1 year ago

Stuff you have to relearn every time you have to use it

😂 If I could summarize my engineering career, that would be the one liner.

[–] [email protected] 3 points 1 year ago* (last edited 1 year ago) (1 children)

wow, I'm impressed, I can't even understand some of the silly regex's I have. It printed an entire explanation of how the regex worked

[–] [email protected] 1 points 1 year ago (1 children)

It doesn't seem to good at writing complex regex though haha

[–] varsock 1 points 1 year ago

Explaining regexs is definitely more of a strength than writing!

Complex regexs require more human intervention or better "prompt engineering" for sure.

I like to build up a regex by "show me a regex that does this. Add to the previous regex to also look for this. Modify previous regex to exclude this, etc etc." That way I can walk Chat-GPT by the hand on what I want. dumping a whole prompt on it gives me poor results

load more comments
view more: next ›