Live data from Hacker News

Show HN: Regex Cheatsheet

ihateregex.io

61–70 of 135 posts

Re: Show HN: Regex Cheatsheet

#61
post #26

Is there a bug? In regexp for IPv4: https://ihateregex.io/expr/ip expression ends with {3} but the diagram states "2 times" in lower right - shouldn't it say "3 times"?

I think it says "repeat 2" times. So basically you'v already went through the group and then 2 more times. Because if I specify x{0,3}, i have 2 paths - around x and thru x + at most 2 more times

Yep you are right

Re: Show HN: Regex Cheatsheet

#62
One thing i've always missed from the Perl programming language is the regex operators.

You could do:

  my $var='foo foo bar and more bar foo!!!';

  if($var=~/(foo|bar)/g){  # does the variable contain foo or bar?

    print "foo! $1 removing foo..\n";

    # remove our value..

    $var=~s/$1//g;

  }

Re: Show HN: Regex Cheatsheet

#64

OK, these kinds of regex tools get posted quite often. I get it, regex is very confusing at first. And some of these use-cases result in rather complex expressions nobody should be forced to write from scratch (you are still remembering to write unit tests for them though, right?) But as someone who actually knows [some flavours of] regex fairly well, what I would really like, is a reference that covers all the subtl…

You're totally right. Right now this tool only supports the javascript flavor of regex. That said, for all the simple expressions shown there it's more or less the same for most other engines. I guess that makes it okay.

Re: Show HN: Regex Cheatsheet

#66
Really nice idea.

I found that you can see your own regex with railroad diagram by going to one of the prepopulated examples and editing it. However, it wasn't clear to me that's the intended use of the tool. It's either a little side-effect, or not super-discoverable.

Re: Show HN: Regex Cheatsheet

#67

OK, these kinds of regex tools get posted quite often. I get it, regex is very confusing at first. And some of these use-cases result in rather complex expressions nobody should be forced to write from scratch (you are still remembering to write unit tests for them though, right?) But as someone who actually knows [some flavours of] regex fairly well, what I would really like, is a reference that covers all the subtl…

The O’Riley book “mastering regular expressions” has a whole section dedicated to it. As well as several tables. But it would be nice to have an online version.

Re: Show HN: Regex Cheatsheet

#68

OK, these kinds of regex tools get posted quite often. I get it, regex is very confusing at first. And some of these use-cases result in rather complex expressions nobody should be forced to write from scratch (you are still remembering to write unit tests for them though, right?) But as someone who actually knows [some flavours of] regex fairly well, what I would really like, is a reference that covers all the subtl…

Honestly, as a noob, this is one of the biggest reasons I have such a hard time deciding to learn regex.

Python flavor would probably be different than PCRE, which is probably different than JS flavor.

Even worse is that it might be too late to standardize all the regex flavors because there is already so much written in different regex flavors that it just costs too much for them to become obsolete in the future.

This is really demotivating.

Re: Show HN: Regex Cheatsheet

#69
Regex are quite simple and useful but my only issue is with those recursive things. Like how do you match balanced brackets? I have a regex (pcre) copy-pasted for it but for the life of me I don't get it or maybe nod my head but instantly ununderstand it. I wish there was a simple to understand doc that teaches to me how I can match something like:

    "(this is inside a bracket (and this is nested or (double nested)))
P.S. I know token parsing is better for these things but still I just want to learn the other thing too.

Re: Show HN: Regex Cheatsheet

#70
post #68

OK, these kinds of regex tools get posted quite often. I get it, regex is very confusing at first. And some of these use-cases result in rather complex expressions nobody should be forced to write from scratch (you are still remembering to write unit tests for them though, right?) But as someone who actually knows [some flavours of] regex fairly well, what I would really like, is a reference that covers all the subtl…

Honestly, as a noob, this is one of the biggest reasons I have such a hard time deciding to learn regex. Python flavor would probably be different than PCRE, which is probably different than JS flavor. Even worse is that it might be too late to standardize all the regex flavors because there is already so much written in different regex flavors that it just costs too much for them to become obsolete in the future. Th…

Honestly don't let this get you down, here's a learning plan (use regex101 to learn)

1) Learn PCRE regex. 2) Try regex golf or cross words to learn PCRE regex. 3) Take the quiz on regex101.

Once you're done with all 3:

Learn the minor/major differences in the other languages. There aren't many. For example this named capture group:

(?someregex)

Would look like this in a different language:

(?Psomeregex)

There's some differences about what language can and cannot do like recursion because someone thought it was a great idea to make javascript awful at regex, but that's besides the point. Regex is totally worth learning.

Post reply on HN