In fact, in my 15 years of coding I never once met someone who know regex really - they all did the same.
Where is this mythical regex guru and how did you learn it! Please share!
I know most of the common operators in a regex by heart but I do have to look up how to use lookahead or lookbehinds here
https://docs.python.org/3/library/re.html
or
https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pa...
because I use them maybe once a year. Another area where people are always getting in trouble with regexes is quoting. That is, you sometimes have to look for a character like '[' which is meaningful in a regex and this can drive you batty when that quoting interacts with other quoting in the language you are using like the quoting in strings or in the bash shell.
If you really want to master regular expressions you ought to understand the theory behind them and how they are implemented,
https://swtch.com/~rsc/regexp/ https://www.cs.princeton.edu/courses/archive/fall12/cos126/l...
Most of my surviving colleagues just use some web-based regex constructor of some sort and they get along mostly fine, but would be lost without it.
Asking around, many of them seem fond of:
Also https://regexcrossword.com/ is pretty fun.
Sometimes I just need to grab all public IPs from AWS stuff to whitelist them for something. With Windows powershell for example, although the regex here is crude and would match non-valid IPv4 adresses, it is enough for logfiles:
$awsIPs = aws ec2 describe-network-interfaces --output=text | Select-String -Pattern ("ASSOCIATION.*\s(([0-9]{1,3}\.){1,3}[0-9]{1,3}$)") | ForEach-Object { $_.Matches.Groups[1].Value } | Select-Object -Unique
Within apps I use them mostly to cut small strings into the respective parts if a simple split doesn't work. I do use them to validate user input regularly, although I don't do user interfaces that often. Not a web developer, but in JavaScript I use them quite often.I still have to look up some rules from time to time.
For designing the regex I often use sites like this: https://regex101.com/ Here you also get a handy reference and error description.
For example, if I want to find a function definition for foo in C and I don't know its return type:
^\s*\w+\s+foo\s*(.*)
That would find it. Probably.
This is not an area of learning how to "code" via examples or trial and error. This is an area that requires the study of computer science, aka math. If you find regex confusing, it means that you do not understand, or have not learned about, some fundamental principles of computer science - regular languages, finite state machines, and regular expressions.
This is not intended to be derisive. It's just a very, very common issue - regular expressions are like the algebra and calculus of computer science. It looks like magic if you don't understand it, but it's not magic - it's obvious if you learn the background.
You can code a lot of code without knowing computer science. But you will not learn regular expressions that way.
another +1 for https://regex101.com, btw.
https://www.cs.princeton.edu/courses/archive/spr09/cos333/be...
I would suggest that if you're struggling with complex regexes, they might not be the right tool for the job and you should write a custom parser instead.
want to get there? use emacs for everything, write a lot, and use replace-regex for all search and replace actions.
note that this took several years of being a full-time, open-source doc person 8x7.
You're right about many people not being fluent in Regex. If you were fluent though, you wouldn't even need to use it that much anyway, so people don't learn it fully. They just Google for patterns that match their criteria.