News for hackers. Stuff that matters.
Re:Ask HN: What's the most valuable thing you can learn in a... by aeternum on Wednesday November 20, 2019 @01:10AM (#21581479)
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.

Re:Ask HN: What's the most valuable thing you can learn in a... by johnlbevan2 on Wednesday November 20, 2019 @06:42AM (#21582997)
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.
Re:Ask HN: What's the most valuable thing you can learn in a... by smbl64 on Wednesday November 20, 2019 @04:48AM (#21582462)
This always helps me in learning and debugging regex: https://regex101.com/
Re:Ask HN: What's the most valuable thing you can learn in a... by danhanlon on Wednesday November 20, 2019 @09:35AM (#21584223)
Haven't done the Regex course, but Gary Bernhardt's https://www.executeprogram.com looks promising and haven't seen it mentioned
Re:Ask HN: What's the most valuable thing you can learn in a... by jeltz on Wednesday November 20, 2019 @05:48AM (#21582730)
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.
Re:Ask HN: What's the most valuable thing you can learn in a... by collyw on Wednesday November 20, 2019 @07:39AM (#21583361)
There is a way of thinking when you deal with regexes that took me a while to get.

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.

Re:Ask HN: What's the most valuable thing you can learn in a... by agungsukma on Wednesday November 20, 2019 @01:31AM (#21581564)
Yes, regular expression. Saves me from lines of substr, split, join, etc.
Re:Ask HN: What's the most valuable thing you can learn in a... by enraged_camel on Wednesday November 20, 2019 @05:00AM (#21582502)
Eh, I always use substr, split and so on if possible. They make the code way easier to read than with a regex.
Re:Ask HN: What's the most valuable thing you can learn in a... by Izkata on Wednesday November 20, 2019 @04:00PM (#21588453)
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)

Re:Ask HN: What's the most valuable thing you can learn in a... by aliceryhl on Wednesday November 20, 2019 @01:37AM (#21581597)
Simple transformations can easily become complex to do with regex, so I've started using vim macros instead.
Re:Ask HN: What's the most valuable thing you can learn in a... by swiley on Wednesday November 20, 2019 @02:23AM (#21581777)
Regex don’t do transformations? All they can do is match strings.
Re:Ask HN: What's the most valuable thing you can learn in a... by leokennis on Wednesday November 20, 2019 @03:36AM (#21582139)
If I have a list of names I’d like to reverse:

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.)

Re:Ask HN: What's the most valuable thing you can learn in a... by jeltz on Wednesday November 20, 2019 @05:52AM (#21582750)
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).

Re:Ask HN: What's the most valuable thing you can learn in a... by aeternum on Wednesday November 20, 2019 @03:09AM (#21582011)
Regex grouping expressions along with find & replace enable transformations.
Re:Ask HN: What's the most valuable thing you can learn in a... by TJSomething on Wednesday November 20, 2019 @03:00AM (#21581973)
Transformation by substitution is part of most dialects of regex, in the form of capturing groups.
Re:Ask HN: What's the most valuable thing you can learn in a... by sauravs on Wednesday November 20, 2019 @02:35AM (#21581847)
agree...regular expression is like magic to me
Re:Ask HN: What's the most valuable thing you can learn in a... by maccard on Wednesday November 20, 2019 @07:06AM (#21583145)
I spent an hour learning the basics - wildcards, whitespace, escape symbols and Character ranges are enough for them to be useful.