Live data from Hacker News

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

refrf.shreyasminocha.me

61–70 of 113 posts

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

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

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

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

That's not really true. The guide seems to be javascript centric. The slash and flags is not part of the regex, it's a delimiter. In certain contexts like sed, perl, php, an arbitrary delimiter can be used to avoid needing to escape slashes. If you pass a string to a regex engine with a /, it does what you would expect, match a literal /. For instance, python and grep does not interpret slashes and flags. Those are pretty common.

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

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

That's not really true. The guide seems to be javascript centric. The slash and flags is not part of the regex, it's a delimiter. In certain contexts like sed, perl, php, an arbitrary delimiter can be used to avoid needing to escape slashes. If you pass a string to a regex engine with a /, it does what you would expect, match a literal /. For instance, python and grep does not interpret slashes and flags. Those are p…

Thanks for the heads up, it seems i have some more reading to do :)

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

#65
I sometimes wonder what a syntactically clarified regex could look like. There are two things that often confuse newcomers:

- What are escapes are and what needs to be escaped?

- The structure of a regex.

- Syntax around things like capture (is the parens part of some matcher? what to escape?)

We should have a version of regex that separates characters, character classes and operators, or whatever the regex jargon for those things are. Half the things I usually want to regex for, like parens on a function or dot accessors need to be escaped!

A quick example for illustration purposes (please don't point out why this grammar wont map to regex):

    (['a' or 'b'], captureAs="prefix")[number or '.']

is definitely more approachable and easier to explain than the regex equivalent (which I'm avoiding to write because I don't have time to test if I got capture syntax right).

Maybe someone makes a wasm regex-simple transformer we can use in multiple languages. Regex is too useful to have such a scary syntax for newcomers!

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

#67
post #66

Maybe I missed it, but there doesn't seem to be any credit given for the xkcd comic ( https://xkcd.com/208/ ) shown on the Next Steps page ( https://refrf.shreyasminocha.me/chapters/next-steps ). Does Randall even require it?

He does require it per CC-BY-NC-2.5. I felt it was sufficient to permalink to the version on his domain, but I shall make it more explicit.

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

#68
post #10

I like the example based approach. I learn from examples far quicker than I learn from “explanations”. If I attempt to learn from an example and my brain hits an exception, only then do I start reading the supporting text. Nice approach. You’ve made a valuable thing and implemented a powerful idea.

I honestly wish a lot more documentations started like that with a bunch of examples. I think one I really enjoyed recently was attrs [0]. [0] https://www.attrs.org/en/stable/examples.html

I've been using tldr [1] instead of man pages lately to get started with a command (or to remind myself how to use one). I've learned a lot just by reading the examples shown, and then read the man pages if I am missing something.

[1] https://github.com/tldr-pages/tldr

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

#69
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.

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

#70
post #65

I sometimes wonder what a syntactically clarified regex could look like. There are two things that often confuse newcomers: - What are escapes are and what needs to be escaped? - The structure of a regex. - Syntax around things like capture (is the parens part of some matcher? what to escape?) We should have a version of regex that separates characters, character classes and operators, or whatever the regex jargon fo…

I think most people just like to hate on regex syntax because when just glanced over it looks like spilled tea leaves.

However I'd argue that it's not actually very hard to learn and its brevity makes it easier to retain. (personally I did so using https://www.regular-expressions.info/tutorial.html)

I agree that escaping is a problem, mainly because languages have often different rules for this.

Post reply on HN