Live data from Hacker News

Show HN: RegEx for Regular Folk – A visual, example-based introduction

refrf.shreyasminocha.me

71–80 of 113 posts

Re: Show HN: RegEx for Regular Folk – A visual, example-based introduction

#71
post #54

This looks really nice but I think it suffers from the same issue a lot of regex tutorials suffer from. It's focusing solely on the regex and not at all on how to actually execute them. This site in particular says it's going to use javascript but at least the first few pages don't show anything except raw regular expressions. For any tutorial about regular expressions I think the second thing (beyond a very simple e…

Good. Unless you’re trying to write a one off script, you shouldn’t manually use them in real world projects. They’re a big source of bugs

I've read this a lot but I've yet to encounter bugs in regexes that wouldn't be otherwise encountered in a parser or validator that uses other techniques. Code is just code.

Re: Show HN: RegEx for Regular Folk – A visual, example-based introduction

#72
It might be nice to touch on composition as a good way to get started is to test out individual pieces and be confident they work when you're putting them together.

If you're building a complex regular expression, setting smaller parts in variables and dropping them in with (?:${part}) makes things a bit more readable.

It also exposes a real weakness of most regex engines. In particular, alternation is a first-class operation, but complement and intersection, while theoretically possible[1] are typically not.

A person might guess that to match three keywords is /.keyword1.&.keyword2.&.keyword3./

Or maybe /.keyword1.&(.keyword2.)!/ to match keyword1 and not keyword2.

But those won't work, so it's a good idea to explain some options, an obvious one being /keyword1/.test() && !/keyword2/.test()

In the section on lookaround assertions, it's probably useful to note that (?=thing1)(?=thing2) can match both, and it's a good mental model for it, but that it comes with a few gotchas.

[1]: https://www.researchgate.net/publication/220994310_Succinctn...

Re: Show HN: RegEx for Regular Folk – A visual, example-based introduction

#73
post #54

This looks really nice but I think it suffers from the same issue a lot of regex tutorials suffer from. It's focusing solely on the regex and not at all on how to actually execute them. This site in particular says it's going to use javascript but at least the first few pages don't show anything except raw regular expressions. For any tutorial about regular expressions I think the second thing (beyond a very simple e…

Good. Unless you’re trying to write a one off script, you shouldn’t manually use them in real world projects. They’re a big source of bugs

“Unless you’re trying to write a one off script, you shouldn’t manually use them in real world projects.”

What should one use instead of manual use?

Re: Show HN: RegEx for Regular Folk – A visual, example-based introduction

#74
I've always wanted to introduce regexes to non-programmers because they have always struck me as staggeringly useful. Just simple things like find/replace in my filenames and find/replace in documents.

This guide, along with a simple web-based regex tester would be great for this...

But it's missing a 3rd part: regex plugins for common non-programmers tools, like for ms office, the windows explorer, etc.

Re: Show HN: RegEx for Regular Folk – A visual, example-based introduction

#76
post #54

This looks really nice but I think it suffers from the same issue a lot of regex tutorials suffer from. It's focusing solely on the regex and not at all on how to actually execute them. This site in particular says it's going to use javascript but at least the first few pages don't show anything except raw regular expressions. For any tutorial about regular expressions I think the second thing (beyond a very simple e…

Good. Unless you’re trying to write a one off script, you shouldn’t manually use them in real world projects. They’re a big source of bugs

Every compiler and interpreter as well as all text formats like HTML, XML, JSON, etc. have a lexing pass that uses manually crafted regular expressions. Those are real world projects.

The defensible form of this argument is that one should prefer a serialization library or a properly normalized database rather than trying to "stringly type" data and then pull it out via regexes.

Re: Show HN: RegEx for Regular Folk – A visual, example-based introduction

#77

This looks really nice but I think it suffers from the same issue a lot of regex tutorials suffer from. It's focusing solely on the regex and not at all on how to actually execute them. This site in particular says it's going to use javascript but at least the first few pages don't show anything except raw regular expressions. For any tutorial about regular expressions I think the second thing (beyond a very simple e…

I agree that it would be nice if the learner was given some instruction on how to experiment right away. I'd recommend https://regex101.com/ as a tool to complement this (or any) regex tutorial, as well as when you're crafting/debugging regex. It's language-agnostic in that you don't need to write any code, just the regex and input -- but you can still pick different regex flavors like PCRE vs JavaScript.

Re: Show HN: RegEx for Regular Folk – A visual, example-based introduction

#78
I think what regex's need is a really powerful syntax and language aware regex editor.

I've been using regexs for most of my career, and still struggle to get them right on first writing.

The #1 problem I run into is:

what is a literal character and what is a control character?

for example, both these are very common:

- match a parenthesis character or a period character

- use a parenthesis to group a match or use a period to match any one character

You would think I would learn it once, and be good.

but my #2 problem confounds this:

what is a literal character and what is a control character - in the language I am using?

for example I might need to escape a period to make it a literal for a regex.

If I am checking the files filexc and file.c and want to match the second, the regex I want is

  ^.*\.c$
in perl, I could say:

  $rx = "^.*\\.c\$";    ($" is a thing)
  if ($f =~ /$regex/) { ...
better would be:

  if ($f =~ /^.*\.c$/) {...
in python I would write

  m = re.search("^.*\\.c$",f)
better would be:

  m = re.search(r'^.*\.c$', f)
in a shell script, I might say:

  grep "^.*\\.c$"
EDIT: crap, I had to escape my comment because the asterisk in the regex was making my text italic

Re: Show HN: RegEx for Regular Folk – A visual, example-based introduction

#79
post #61

Nice guide! As a complete regex-dyslectic i didn't know the slash '/' could be used to make expressions more readable. On another note, since this is supposed to be a book and all, is there a simple way to get this on one a single page and make it easier to print?

> is there a simple way to get this on one a single page and make it easier to print? That's on my TODO! - https://github.com/shreyasminocha/regex-for-regular-folk/iss... - https://github.com/shreyasminocha/regex-for-regular-folk/iss... I was having some trouble with wkhtmltopdf, but I'll try to figure this out ASAP.

I don't know what that is but just having all html pages merged into one would be enough and super useful for me and my printing purposes, and probably good for web UX too. Keep up the good work mate

Re: Show HN: RegEx for Regular Folk – A visual, example-based introduction

#80
post #78

I think what regex's need is a really powerful syntax and language aware regex editor. I've been using regexs for most of my career, and still struggle to get them right on first writing. The #1 problem I run into is: what is a literal character and what is a control character? for example, both these are very common: - match a parenthesis character or a period character - use a parenthesis to group a match or use a…

Do you think an extension for vscode might be worth it?
Post reply on HN