Live data from Hacker News

Learn RegEx step by step, from zero to advanced

regexlearn.com

21–30 of 114 posts

Re: Learn RegEx step by step, from zero to advanced

#21
post #8

>Regular Expressions, abbreviated as RegEx or RegExp, are a string of characters created within the framework of RegEx syntax rules. You can easily manage your data with RegEx, which uses commands like finding, matching, and editing. Regex can be used in programming languages such as Phyton, SQL, Javascript, R, Google Analytics, Google Data Studio, and throughout the coding process. Learn regex online with examples a…

For heavy optimizations, I've learned that looping through each char and maybe passing in an array of illegal or preferred chars is faster than Regex. It's about 2-2.5x the speed from my basic example.

So if you're processing lots of stuff, manual loops might be better. If not, Regex is the way to go.

Re: Learn RegEx step by step, from zero to advanced

#22

I learn regex just before I need it. Every. Time. After 25 years, it just doesn't stick.

Why use it though? I'd rather wright or read 30 lines of code instead of trying to decipher what a regex means or do and making sure it is covering all possible cases.

I don't understand the goodwill toward regexes. It's basically an embedded BrainFuck in your programming language.

I'm 14 years in my dev career, there never was a moment where not using regexes came to be a problem.

Re: Learn RegEx step by step, from zero to advanced

#23
post #5

started by adding "ok" in the first lesson... lock just shakes and when clicking the answer, it shows the exact same thing thats already in the box :/

You need to press enter/return to advance.

Actually, it needs to be uppercase "OK". I typed "ok" also, and scratched my head for a while. I get it should be obvious, but my brain just didn't get it right away.

Re: Learn RegEx step by step, from zero to advanced

#24

I learn regex just before I need it. Every. Time. After 25 years, it just doesn't stick.

I was excellent at regex early in my career... actually had a job where that's basically all I did for 9 months. Read the O'Reilly book Mastering Regular Expressions from cover to cover and referenced it multiple times per day. Doing regex at a high level was instinctual.

Lost much of that knowledge within a couple years after leaving that job... was shocked how much wasn't retained when I stumbled into another project that required a fair bit of regex work. There was some muscle memory involved and I was able to ramp up quickly, but now 20 years after that initial job I'm just like you.

Re: Learn RegEx step by step, from zero to advanced

#25

I learn regex just before I need it. Every. Time. After 25 years, it just doesn't stick.

I simply don't want to memorize 3 or more different versions of the syntax codes.

Sometimes I'm using .Net. Sometimes I'm using Python. Sometimes I'm using whatever oddball engine the developer chose.

I know how regex works. I can use forward and backward references. I can combine complex patterns. I can match, extract, replace, transform, etc. Sometimes I have even used nested patterns (though I'd probably need half an hour to re-learn it well enough to read one). But I'm not sitting down and memorizing the difference between /d and /D, or \S and \w or any of that. Frankly, I'm very lucky if I remember the difference between ^ and $. I will have the .Net[0] and the Python[1] doc in my bookmarks forever.

I'm not remotely ashamed of it, either. The codes are completely arbitrary with absolutely no intrinsic meaning. Worse, it's not easy to tell the difference at a glance between literal characters, character classes, operators, wildcards, special constructs, etc. More than once I've been confused by a regex only to discover it does something I didn't know they could even do. Regex patterns are meant to be concise and comprehensible to the regex engine, not to the programmer.

Don't feel bad because you don't memorize an arbitrary and complex syntax. Memorizing syntax is not the job of a programmer. The job of a programmer is to compose the logic and design the system and know that a syntax exists to compose it in. A programmer is an author, not a linguist.

[0]: https://docs.microsoft.com/en-us/dotnet/standard/base-types/...

[1]: https://docs.python.org/3/howto/regex.html

Re: Learn RegEx step by step, from zero to advanced

#27
post #8

>Regular Expressions, abbreviated as RegEx or RegExp, are a string of characters created within the framework of RegEx syntax rules. You can easily manage your data with RegEx, which uses commands like finding, matching, and editing. Regex can be used in programming languages such as Phyton, SQL, Javascript, R, Google Analytics, Google Data Studio, and throughout the coding process. Learn regex online with examples a…

> I always look at these intros/descriptions of Regex with a heavy heart. They describe what regex's are, but none of the info is going to make much sense to someone who doesn't already know why they would want to learn them.

> Catch 22 of trying to explain what they are.

any teachers, or people who explain/document things for a living, have some good tips or templates to avoid this?

Re: Learn RegEx step by step, from zero to advanced

#28
post #8

>Regular Expressions, abbreviated as RegEx or RegExp, are a string of characters created within the framework of RegEx syntax rules. You can easily manage your data with RegEx, which uses commands like finding, matching, and editing. Regex can be used in programming languages such as Phyton, SQL, Javascript, R, Google Analytics, Google Data Studio, and throughout the coding process. Learn regex online with examples a…

> I always look at these intros/descriptions of Regex with a heavy heart. They describe what regex's are, but none of the info is going to make much sense to someone who doesn't already know why they would want to learn them. > Catch 22 of trying to explain what they are. any teachers, or people who explain/document things for a living, have some good tips or templates to avoid this?

I don't see what's so hard.

"With regex you can search for any combination of characters in a string or return any such combo or modification you like"

Re: Learn RegEx step by step, from zero to advanced

#29
post #17

I learn regex just before I need it. Every. Time. After 25 years, it just doesn't stick.

I'm the same way. I suppose some people use regex's a lot, I never really have. If our experiences are typical, I'd argue people new to regex's should more learn they exist and when they can be useful, and not worry too much about actually learning their mechanics.

This was my approach and I found it pretty successful the first and most recent time I used regex.
Post reply on HN