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
Show HN: RegEx for Regular Folk – A visual, example-based introduction
71–80 of 113 posts
Re: Show HN: RegEx for Regular Folk – A visual, example-based introduction
#72If 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
#73This 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
What should one use instead of manual use?
Re: Show HN: RegEx for Regular Folk – A visual, example-based introduction
#74This 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
#75Re: Show HN: RegEx for Regular Folk – A visual, example-based introduction
#76This 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
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
#77This 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…
Re: Show HN: RegEx for Regular Folk – A visual, example-based introduction
#78I'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 italicRe: Show HN: RegEx for Regular Folk – A visual, example-based introduction
#79Nice 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.
Re: Show HN: RegEx for Regular Folk – A visual, example-based introduction
#80I 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…