Regular expressions fall into this category. While they might take longer to master, you should know the basics after an hour.
I've been surprised at how often people convert long lists line-by-line. You can sometimes take what was a multiple-hour task and complete it with a handful of cryptic characters.
It really depends on what you're doing, and at least being aware of what regex can do will help with deciding which is better for a given situation.
For example, I remember once replacing a buggy 3-4 lines of python based on split/etc with a single regex: match all \d+ (it was for extracting IDs from a user-input string)
John Smith > Smith, John
Anna Peterson > Peterson, Anna I can write: (.) (.) And replace with: \2, \1 Not sure if that’s part of some “official” regex spec but it works more or less everywhere. (Of course if it was an actual list of names I’d have to be a lot more intelligent with double names etc.)
Almost. All regular expressions do is match strings and find the starts and ends of whole matches and match groups. And this is an important distinction since match group support adds quite a bit of complexity to the theory behind regular expressions and also increases their usefulness by quite a bit.
Regular expression libraries then often can use these boundaries, for the whole match and for groups, for transform the string (e.g. replacing what was matched by a group with some other content).
Can you really learn regex in one hour? I learned them so long time ago and in a gradual way that I have no idea how long it would take if you focus on it, but I feel like it would be more than an hour since I think most people would need to play around quite a bit to really grasp them.
I found this site fantastic for improving my RegEx skills - https://regexcrossword.com/. Most people find solving puzzles more fun than reading text books, and the hands-on experience / forcing you to think rather than just read, can really help things stick in your memory.
I've been surprised at how often people convert long lists line-by-line. You can sometimes take what was a multiple-hour task and complete it with a handful of cryptic characters.
For example, I remember once replacing a buggy 3-4 lines of python based on split/etc with a single regex: match all \d+ (it was for extracting IDs from a user-input string)
John Smith > Smith, John Anna Peterson > Peterson, Anna
I can write:
(.) (.)
And replace with:
\2, \1
Not sure if that’s part of some “official” regex spec but it works more or less everywhere.
(Of course if it was an actual list of names I’d have to be a lot more intelligent with double names etc.)
Regular expression libraries then often can use these boundaries, for the whole match and for groups, for transform the string (e.g. replacing what was matched by a group with some other content).
Reading the first chapter of ORiley's Mastering Regular Expressions was what made me get it and that was maybe an hours worth of time.