Which tool to choose
A regex (regular expression, the formula for searching text patterns like dates, codes, emails) is generated well by any general-purpose AI assistant in the free version. If you'll use it inside a code editor, the assistant integrated there is preferable: it already sees what language you write in and proposes the right syntax without your having to remind it every time.
Dedicated regex generators exist, but for non-programmers the conversational assistant wins on one thing: it explains. It tells you why that symbol is there, and so the next time you need it a little less.
How to do it
The risk of an AI-generated regex is just one: it works on the example and breaks on the real case. You avoid it by giving the AI concrete examples of what it must capture and what it must not.
- Open a chat and declare the language or the tool: "regex for Google Sheets," "regex for Python," "regex for Word's find-and-replace function."
- Describe what to search for in your own words and give two or three real examples of text it must capture.
- Add an example of text it must NOT capture: it's the detail that separates a correct regex from one that grabs too much.
- Ask for the regex plus an explanation of each part.
- Test the regex on your examples before using it on the real data.
The operational syntax:
Write me a regex for Python that finds all Italian phone numbers in a text.
It must capture: +39 333 1234567, 333-123-4567, 3331234567
It must not capture: 12345, 2024 (years), 192.168.1.1 (IP addresses)
Give me the regex and explain each part in one line.
When the answer arrives, paste in some real text of yours and ask: "Apply this regex to this text and tell me what it captures." You see right away whether it grabs what you need or not.
A concrete example
Giulia has a sheet with five hundred email addresses mixed in with names and notes, and she needs to isolate only the domains (the part after the at sign). She writes: "regex for Google Sheets that extracts only the domain from an email, example: from [email protected] I want gmail.com." The AI gives her the formula with REGEXEXTRACT and the explanation. Giulia tests it on three cells, sees it works, drags it across all five hundred. Half an hour of copy-paste saved.
When it does NOT work (and how to fix it)
If the regex works in one place but not in the other
Regexes aren't all alike: the syntax changes between Python, JavaScript, Excel and the others. If the AI gave you named groups and your tool doesn't accept them, it's because it guessed the wrong language. Go back and explicitly declare where you'll use it: "this has to work in JavaScript," and ask it to rewrite it in that syntax.
If it captures too much or too little
Almost always the negative examples are missing. Correct the AI with the cases it got wrong: "it also took '2024', it shouldn't; here are three more examples to exclude." The regex is refined by giving it counterexamples, not by re-explaining the rule in words.
If you don't understand the regex and are afraid to use it
Ask the AI to translate it into a test you can read: "write three example sentences, two that the regex captures and one it ignores, so I can verify." If the three examples come out right, the regex does what you think, even if the symbols stay obscure.
A tip from someone who actually uses it
Always ask for the explanation, even when you're in a hurry. Not to study, but because the explanation lets you discover the AI's misinterpretation before you send a wrong regex into production. If in the explanation you read "captures any sequence of digits" and you wanted only ten-digit ones, you see it there, not later on the real data.
Frequently asked questions
Do I need to know what a regex is to have one written for me?
No, it's enough to be able to describe in words what you want to find and to give examples. The regex is exactly the kind of awkward syntax it's worth delegating to the AI: you bring the examples, it brings the symbols.
Can I use it to find and replace inside Word or a text editor?
Yes, many editors have search with regex (sometimes called "advanced search" or "regular expressions"). Declare to the AI which program you use, because the accepted syntax changes from one to another.
Does the AI ever get a regex wrong?
Yes, especially on the edge cases you haven't shown it. That's why the negative examples matter more than the description: a regex tested on real data is worth it, one accepted on trust is not. Never put it to work on important data without a test run.