Live data from Hacker News

Show HN: Regex Cheatsheet

ihateregex.io

121–130 of 135 posts

Re: Show HN: Regex Cheatsheet

#121
post #81
post #39

Earlier quoted context omitted.

Even that is wrong because you can have privately owned TLDs (I forget what they're technically called) like .google So sundar.pichai@google is technically a valid address (whether .google has any MX records is another matter) Regex shouldn't really be used for email addresses anyway because the only reliable way to authenticate an email address is to literally send an email to that address.

AFAIK none of the TLDs allow for MX records on just the TLD i.e. johndoe@com will never exist

I'm not on about gTLDs like .com, I'm on about the privately owned ones like .amazon and .google

Re: Show HN: Regex Cheatsheet

#124
post #93

Would be nice to have a regex for parsing HTML... grabs popcorn

boom. https://regex101.com/r/PxSY4U/1 technically it does parse it. :P

Nope. bar">My First Heading will misparse. (This is valid HTML 5.) You really need recursive regex or something equivalent in power, otherwise you will always fail.

Re: Show HN: Regex Cheatsheet

#125

Earlier quoted context omitted.

RE2 syntax[1] is a pretty good option to learn, because it's mostly a "lowest common denominator" - if it works in RE2, it should work in PCRE, Python, Javascript, etc. The reverse isn't true - there is a bunch of syntax that RE2 doesn't support by design, often to constrain performance bounds. Emacs regexps are unfortunately their own weird beast - they handle parentheses differently than other regexp engines, becau…

IME Emacs provides a very pleasant way to write regexps using the rx library. ELPA also has the package xr, which converts Elisp regexps to rx format, and pcre2el converts PCRE to Elisp. So a regexp like \b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b Can easily be converted like: (->> "\\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\\b" pcre-to-elisp xr) To: (seq word-boundary (one-or-more (any "0-9A-Z" "%+._-")) "@" (one-or-m…

Agreed that rx is nice, but really only useful if you're writing elisp. 90%+ of people who need to interact with Emacs regexps aren't writing an elisp program - they're using Emacs interactively, or even using another program (busybox, GNU find, etc.) that uses Emacs regexps for historical reasons. For those people the differences in syntax between Emacs regexps and "normal" regex dialects are a pain.

Re: Show HN: Regex Cheatsheet

#127
post #90

Earlier quoted context omitted.

> Honestly, as a noob, this is one of the biggest reasons I have such a hard time deciding to learn regex. Clear your afternoon, and just learn it. Seriously, it takes a couple of hours at best and then - BOOM - you're done for the rest of your life.

> you're done for the rest of your life. If that were so easy then I don't think much of these cheatsheets would exist.

The cheat sheets exist because people aren’t learning regex. You don’t need to learn every flavor of regex, just the one or small number you need to know. And once you know the basics, the differences are very minor.

Re: Show HN: Regex Cheatsheet

#128
post #83
post #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; }

So did I: https://github.com/radiac/python-perl/

Awesome job, i did a hack bootstrapping the tokenizer to do the same thing in php, didn't release it though.

Re: Show HN: Regex Cheatsheet

#129

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.

And it's one one the best O'Reilly books. I went and checked because of your comment and just noticed there was a third edition that I missed, I have the second. Still a book worth studying.

Re: Show HN: Regex Cheatsheet

#130
post #29

This is awesome but.... I don't hate regex. Matter of fact, I love regex.

check out the ipv6 one :)

I've had to write regex for deeply proprietary SQL-like (the word "like" is a big BIG stretch) language. This really is nothing. The regex itself was 4 pages long. AFAIK they still use it in production, almost 10 years later with 0 modifications.

¯\_(ツ)_/¯

Post reply on HN