Re:Common Regular Expressions Made Simple
by brudgers on Tuesday December 17, 2013 @08:02AM
(#6920851)
I am reminded of VerbalExpressions https://github.com/VerbalExpressions which hit HN in early August. Interested in learning more about regex's I did some work on a Racket port.
That project shows there are two tracks by which to tackle the problem that regex syntax is incoherent gobbledygook. The first is creating a regex version of pho with 5000 functions and mix and match names piece by piece. The second is to rename regex symbols to something that is easier for humans to parse.
Re:Common Regular Expressions Made Simple
by yconst on Tuesday December 17, 2013 @10:47AM
(#6921708)
Very good point! It's not the reasoning and logic behind regex that would turn a beginner away from it, its the syntax that is being used that often results into expressions turning into impenetrable goo!
(thanks for the verbal expressions link btw, seems really promising)
Re:Common Regular Expressions Made Simple
by JadeNB on Tuesday December 17, 2013 @04:08PM
(#6923985)
Unless I'm not understanding my way around the project, this seems to be a very small library of regular expressions. As one would expect, Perl's offerings blow anything else out of the water: http://search.cpan.org/~abigail/Regexp-Common-2013031301/lib....
Re:Common Regular Expressions Made Simple
by abolibibelot on Tuesday December 17, 2013 @06:03AM
(#6920493)
I'm gonna be That Other Guy and say that the date and phone regex are respectively english-language and US specific. So it's common for a narrow definition of common.
Re:Common Regular Expressions Made Simple
by jrabone on Tuesday December 17, 2013 @07:11AM
(#6920671)
Haha that's excellent. Reminds me of a normalisation rule I wrote as part of a larger system to convert "Joe Bloggs Md." into "Dr. Joe Blogs MD" (where MD is Medical Doctor). TIL that "Md." is a common abbreviation for "Mohammed" in large parts of the world...
Re:Common Regular Expressions Made Simple
by petepete on Tuesday December 17, 2013 @09:26AM
(#6921217)
The text-to-speech system in use at my local GP's surgery (that announces to patients which which rooms they need to go to) pronounces 'Dr' as 'Drive', rather than 'Doctor'. I thought someone would have tested that!
Re:Common Regular Expressions Made Simple
by madisonmay on Tuesday December 17, 2013 @11:38AM
(#6922025)
Yeah, I threw together this module intending to supplement NER on a text classification project I'm currently working on, not as a replacement for NER.
Re:Common Regular Expressions Made Simple
by zoj_bad on Tuesday December 17, 2013 @06:28AM
(#6920560)
I'm gonna be That Other Other Guy and say....stuff like this is the reason why most programmers I meet take ages to do anything custom. Evey body uses this framework and that library and make bulky code that could actually be implemented with 2 far more efficient lines and will struggle when the need to customize presents itself. Learn Regex...you will have a crazy powerful weapon in your arsenal.
Re:Common Regular Expressions Made Simple
by vezzy-fnord on Tuesday December 17, 2013 @09:47AM
(#6921334)
Why is this being downvoted?
This is an excellent point. Petty substitutions like verbal expressions might be useful if you're just getting started, but ultimately it's a crutch and it's best just to learn pure regular expressions. They're not that difficult.
Same with bundling a ton of dependencies. Lots of people (especially contemporary programmers, primarily web developers) seem to be deathly afraid of writing custom code to handle a job. It's not "reinventing the wheel", it's implementing logic easily extensible within your application without the hassle of upstream, especially if you're only using a small portion of a library or framework. Using 15 libraries for a 600-line script isn't best practice, it's cowardice.
Re:Common Regular Expressions Made Simple
by bollockitis on Tuesday December 17, 2013 @10:20AM
(#6921546)
There are pros and cons to both approaches. If I see a junior developer trying to reinvent the wheel, he's probably going to build a pretty shitty wheel. The whole point of using dependencies isn't laziness or cowardice, it's leveraging others' work to save time, energy, and potential headaches caused by subpar custom implementations. Of course, that doesn't absolve us from learning the guts of our dependencies, but chastising developers for avoiding unnecessary work is absurd. The key is in learning when to import and when to DIY.
Re:Common Regular Expressions Made Simple
by masklinn on Tuesday December 17, 2013 @09:40AM
(#6921299)
Doesn't really apply here, the goal is to detect the existence of a (potential) email address in the text, you can poke the SMTP server once you've found something address-looking to ensure that it's an address and not, say, a twitter thing.
Re:Common Regular Expressions Made Simple
by ygra on Tuesday December 17, 2013 @07:26AM
(#6920717)
It's not validation in this case, it's finding them in a body of text. For validation you generally have it easier because you often only deal with a single datum in a field (and thus string).
Re:Common Regular Expressions Made Simple
by masklinn on Tuesday December 17, 2013 @08:02AM
(#6920850)
The CLDR provides locale-specific formats for some datum types (IIRC numbers, dates, and durations). These formats can probably be reversed into the corresponding regular expression in order to perform locale-aware data detection.
Of course further complexity is added in people being able to provide partial and context-dependent information, which is much harder to detect e.g. "December 3rd"
That project shows there are two tracks by which to tackle the problem that regex syntax is incoherent gobbledygook. The first is creating a regex version of pho with 5000 functions and mix and match names piece by piece. The second is to rename regex symbols to something that is easier for humans to parse.
(thanks for the verbal expressions link btw, seems really promising)
generally, very good.
> There is always a well-known solution to every human problem — neat, plausible, and wrong.
often paraphrased as "For every complex problem there is an answer that is clear, simple, and wrong."
> um 6:00 am 05.12. (at 6:00 on 12/05/..)
If i read it correctly, the time regex would extract "6:00 am" as time, but the "am" is wrong (German uses 24h format).
Simple regular expressions can be good enough if you're aware of the domain restriction though.
This is an excellent point. Petty substitutions like verbal expressions might be useful if you're just getting started, but ultimately it's a crutch and it's best just to learn pure regular expressions. They're not that difficult.
Same with bundling a ton of dependencies. Lots of people (especially contemporary programmers, primarily web developers) seem to be deathly afraid of writing custom code to handle a job. It's not "reinventing the wheel", it's implementing logic easily extensible within your application without the hassle of upstream, especially if you're only using a small portion of a library or framework. Using 15 libraries for a 600-line script isn't best practice, it's cowardice.
> Please note that this module is currently English/US specific.
http://site.icu-project.org/
I'm sure there are better alternatives than just regexp to validate numbers, emails ,etc ...
Of course further complexity is added in people being able to provide partial and context-dependent information, which is much harder to detect e.g. "December 3rd"