4 ms·
Seriously... https://blog.codinghorror.com/regular-expressions-now-you-have-two-problems/ https://blog.codinghorror.com/regular-expressions-now-you-ha.... And t
by brohee 7y ago
Seriously... https://blog.codinghorror.com/regular-expressions-now-you-have-two-problems/ https://blog.codinghorror.com/regular-expressions-now-you-ha.... And this piece of computer trivia archeology http://regex.info/blog/2006-09-15/247 http://regex.info/blog/2006-09-15/247
- laumars 7y ago> Seriously... https://blog.codinghorror.com/regular-expressions-now-you-have-two-problems/ https://blog.codinghorror.com/regular-expressions-now-you-ha... . The key words I used were "most" and "simple". I'm well aware of the pitfalls of regex and have seen many horror stories myself but I'm not talking about parsing HTML nor other complex documents and nor am I suggesting you write the entire parser in regex. I'm talking about simple find and replaces for common static tags when you're only supporting a subset of BBcode. eg: form := "this is just a [b]crude[/b] example" rx := regexp.MustCompile(`\[b\](.*?)\[/b\]`) form = rx.ReplaceAllString(form, `<strong>$1</strong>`) fmt.Println(form) (https://play.golang.org/p/GK7OGt2mHb6 https://play.golang.org/p/GK7OGt2mHb6) You could even use string find/replace but that wouldn't capture missing closing tags. Things obviously get more complicated if you want to support some of the BBCode supersets like: click [url=example.com]here[/url] to load example.com ...but by that point you're dealing with a reasonably competent contributor who might feel better at home with markdown anyway (I know I would). > And this piece of computer trivia archeology http://regex.info/blog/2006-09-15/247 http://regex.info/blog/2006-09-15/247 Doesn't feel much like archaeology to me because I used to work a lot in Perl in the late 90s and 00s :) Though, and at risk of re-igniting old flamewars, I always preferred vi to emacs even despite having a fondness for LISP.
- CarlRJ 7y ago> Though, and at risk of re-igniting old flamewars, I always preferred vi to emacs even despite having a fondness for LISP. That's because vi is a better text editor (as the old saw goes, emacs is a nice OS, but it lacks a decent text editor.)