Live data from Hacker News

My favorite regex of all time

catonmat.net

101–110 of 117 posts

Re: My favorite regex of all time

#101
post #87
post #9

Earlier quoted context omitted.

Yea, anytime I use a regex that isn't immediately obvious I put it in a function called get_ . Unfortunately people that write overly complicated and error prone regexes usually don't choose to document them.

If a regex is going to be reusable, then yeah, I'd agree. But dumping single lines of code into their own functions just for readability isn't practical for real time systems. In those cases you really should be using comments as they get stripped out by the compiler.

Shouldn't most compilers (jit-)inline it?

Re: My favorite regex of all time

#102
post #87

Earlier quoted context omitted.

If a regex is going to be reusable, then yeah, I'd agree. But dumping single lines of code into their own functions just for readability isn't practical for real time systems. In those cases you really should be using comments as they get stripped out by the compiler.

Couldn't those functions just be inlined by the compiler if they're simple regex-wrappers anyway? I do agree that it might be overkill to move regexes to their own functions just for readability's sake but I don't buy the performance argument. Furthermore, regexes are most popular in scripting languages that no sane person would use for real time performance-critical systems anyway.

1. Ahh right. I wasn't aware that happened.

2. Web sites are a classic example of scripting languages being used for real time performance critical systems (though I'm not arguing that all web sites are real time).

Sometimes the ability to modify code easily is as important to the choice of languages as the raw execution speed of the compiled binaries.

Re: My favorite regex of all time

#105
post #52

Earlier quoted context omitted.

I'm not sure who the PHB is, but I'm certainly not impressed by anything cryptic in a codebase. Deliberately writing code that's hard to understand should be a firing offense.

PHB: Pointy Haired Boss

In that case, the smart thing to do is not to work for the PHB, rather than pervert your craft in an attempt to impress him/her.

Re: My favorite regex of all time

#106
post #37

Earlier quoted context omitted.

Search "[ -~]" (with or without quotes) to see how good Google's comment is.

The only ambiguous thing about this regex is knowing what's between space and tilde. Otherwise this is a pretty ordinary regex.

Hey, might just be me. I'm usually the 'Ben, can you help me with a regular expression' guy over here, but I stumbled, hard, and failed to connect the '-' with a range of characters (probably because I never thought of 'space to .. something').

So I read the snippet, thought 'Yeah, a character class of space, -, ~' and fell on my face in the next couple of lines.

Yeah, I should've known better, I know how to read it. If .. I invest the time and don't glance over a construct and hope to just get it instantly.

I wouldn't want to see this in a code base without proper documentation (be it a comment, a function name or whatever. Something).

Re: My favorite regex of all time

#107
post #87
post #9

Earlier quoted context omitted.

Yea, anytime I use a regex that isn't immediately obvious I put it in a function called get_ . Unfortunately people that write overly complicated and error prone regexes usually don't choose to document them.

If a regex is going to be reusable, then yeah, I'd agree. But dumping single lines of code into their own functions just for readability isn't practical for real time systems. In those cases you really should be using comments as they get stripped out by the compiler.

REGEXES aren't practical for real time systems.

If you're using a regex, and certainly if you're using a language other than C, you probably have space for the function call overhead.

Re: My favorite regex of all time

#108

Earlier quoted context omitted.

Couldn't those functions just be inlined by the compiler if they're simple regex-wrappers anyway? I do agree that it might be overkill to move regexes to their own functions just for readability's sake but I don't buy the performance argument. Furthermore, regexes are most popular in scripting languages that no sane person would use for real time performance-critical systems anyway.

1. Ahh right. I wasn't aware that happened. 2. Web sites are a classic example of scripting languages being used for real time performance critical systems (though I'm not arguing that all web sites are real time). Sometimes the ability to modify code easily is as important to the choice of languages as the raw execution speed of the compiled binaries.

[deleted]

Re: My favorite regex of all time

#109
post #24

Earlier quoted context omitted.

Thank you for that. You have no idea how annoying it is to port perl scripts from ASCII to EBCDIC when they do that kind of thing.

It's not an ASCII v EBCDIC thing, its an ASCII vs Unicode thing.

It's both, but ASCII vs. EBCDIC is worse. Even in Unicode, the regex will still grab the printable characters that also happen to be part of ASCII: you won't see anything wrong until you get to characters outside that range. In EBCDIC, things get much hairier: it won't get capital letters, nor lowercase letters from r through z (but it will get all the other lowercase letters), nor brackets or braces (though it will get parens).

Re: My favorite regex of all time

#110
post #93

Earlier quoted context omitted.

> Who's filenames aren't unicode? Many filesystems don't support unicode or support only a subset of it: https://en.wikipedia.org/wiki/Filename#Comparison_of_filenam... > Also domains and URLs can be unicode too. Domains: it depends at which level you are dealing with them. See https://en.wikipedia.org/wiki/Internationalized_domain_name Internationalized domain names are stored in the Domain Name System as ASCII stri…

http://www.ebækur.is

exists in DNS as xn--ebkur-tra.is
Post reply on HN