Live data from Hacker News

Learn RegEx step by step, from zero to advanced

regexlearn.com

81–90 of 114 posts

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

#81
post #40
post #37

Earlier quoted context omitted.

It very much depends what the use case is. I find that a lot of the text processing I do is easier to use back references or other regexy things. Having said this, I use tools that make regexes easy to use and readily available - I think in many programming languages the syntax means that other solutions are just as easy to devise and implement.

If you are a solo dev, you do you, but if you are working in a team and you are building huge regexes with back references and other bells and whistles... I would guess it's not very readable for your teammates. At least for me, when I look at such a regex I have to stare at it for minutes before grokking it.

Regexps are fairly terse and replace a lot of code, compared to most languages they probably have an information density at somewhere between 10x-100x higher (i.e. it's not rare to replace 100 lines of code with 1 regex), so I think it's fair to expect it take longer to unpack their meaning.

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

#82
post #40
post #37

Earlier quoted context omitted.

It very much depends what the use case is. I find that a lot of the text processing I do is easier to use back references or other regexy things. Having said this, I use tools that make regexes easy to use and readily available - I think in many programming languages the syntax means that other solutions are just as easy to devise and implement.

If you are a solo dev, you do you, but if you are working in a team and you are building huge regexes with back references and other bells and whistles... I would guess it's not very readable for your teammates. At least for me, when I look at such a regex I have to stare at it for minutes before grokking it.

Wold that be a reasonable time to ping that coworker and ask them "what does this do?". Not because you can't figure it out, but because they already know?

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

#84
post #52

Earlier quoted context omitted.

> 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?

Yeah. 1) Encourage whoever you're teaching to stop you immediately if they don't feel like they understand something you're saying, even if it's a single word that's throwing them off, and especially if they're not rock-solid about a simple concept they "should already know". Modern school teaches people that "returning to the basics" is a waste of time; but as Feynman says, you should return to the basics often, as…

Good answer. I think 2) is the one that jumped out at me because it reflected my own experience and understanding - Regex became easier to understand when I also felt like I understood its motivations. Starting there, with motivation and context, is my typical go-to move.

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

#85
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 think regex is absolutely terrible garbage. It’s very powerful, I do appreciate not having to write complex conditional statements, and it’s great that it’s available is so many languages and applications. But it’s just a bad tool, terribly unreadable, easy to introduce bugs, with lots of trial and error. It has too much brevity and would be much better if it were longer but more human readable. I’m sure there are…

https://github.com/AbhinavOmprakash/luna

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

#86
I respect regex for being a widespread DSL that makes certain things very declarative.

My problem with it (other than all the different flavors—that’s just history’s fault) is that you don’t tend to get integrated help/tool support for them. They are often just plain strings—how is e.g. Intellij supposed to spot them reliably and help you?

It’s too bad if we have to copy and paste regex strings into websites in order to figure out what they do.

The number one most useful tool support in my book would just be to highlight metacharacters. Are parens a metacharacter in the dialect that I am using now? Is `+` significant?

A bigger ask would be more verbose regular expression declarations and compilers that can translate to and from them. It’s nice if you can use comments in a regex dialect, but comments should be treated like they are treated in code writ large; don’t use them if you can make the code “self-describing”. Imagine a more verbose declaration language where you can make local aliases, for example `let ident = [a-z][a-z1-9_]*`.

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

#87
I found logstash's Grok a good tool because it is composable and you can reuse complex expressions with simpler naming. There is also a knowledge base of good regex you can use without reinventing the wheel. Rubular.com is also a great tool for working out regex matches.

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

#88

I respect regex for being a widespread DSL that makes certain things very declarative. My problem with it (other than all the different flavors—that’s just history’s fault) is that you don’t tend to get integrated help/tool support for them. They are often just plain strings—how is e.g. Intellij supposed to spot them reliably and help you? It’s too bad if we have to copy and paste regex strings into websites in order…

I agree that it would be nice to get native syntax highlighting for strings, especially for languages where regular expressions are not a first class feature

However, I would realllyyy not want to have a more verbose regex dialect. For me at least, it would make recognizing common regex patterns a lot harder since they won't be succinct. It would also be yet _another_ regex variety that I would have to remember.

For me, Perl's DEFINE feature and 'x' switch are definitely close enough[1] to variables and comments. Pardon, I don't remember what they are officially called. What we really need is for more non PCRE engines to implement these features

[1]: https://regex101.com/r/z5pGvZ/6

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

#89
I don't remember why, but I learned regexes maybe my sophomore year of college because it seemed like such an interesting thing that I might need some day? I also started to learn SQL about the same time. Those feel like herculean efforts so foreign now because I've been using them for so long.

One day at my second job out of college, I wrote a quick regex for something, and one of my more senior colleagues looked at me like I was a wizard. It was amazing to be able to get some street cred for that. To me, it validated the effort I went through previously.

I'm trying to learn about SAT/SMT solvers now. Not because I have a pressing need for them but because it's a completely foreign thing that - who knows? - maybe I'll be able to put to good use today. The problem with SAT/SMT is that there are nowhere near the clear learning resources compared with, say, regexes.

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

#90

I respect regex for being a widespread DSL that makes certain things very declarative. My problem with it (other than all the different flavors—that’s just history’s fault) is that you don’t tend to get integrated help/tool support for them. They are often just plain strings—how is e.g. Intellij supposed to spot them reliably and help you? It’s too bad if we have to copy and paste regex strings into websites in order…

Julia has a "readable regex" library that uses descriptive English names. It's a lot like a SQL query builder, but it builds regex.

https://discourse.julialang.org/t/ann-readableregex-jl/43450

https://github.com/jkrumbiegel/ReadableRegex.jl

Post reply on HN