

Regular Expressions in 100 lines of Scala - rusbus
http://rcoh.svbtle.com/no-magic-regular-expressions

======
hello_there
It's not so easy to see in the linked article, but the article is actually in
3 parts:

Part 1: [http://rcoh.svbtle.com/no-magic-regular-
expressions](http://rcoh.svbtle.com/no-magic-regular-expressions)

Part 2: [http://rcoh.svbtle.com/regular-expressions-
part-2](http://rcoh.svbtle.com/regular-expressions-part-2)

Part 3: [http://rcoh.svbtle.com/no-magic-regular-expressions-
part-3](http://rcoh.svbtle.com/no-magic-regular-expressions-part-3)

It's really well done!

------
WoozyBeet
There is a similar chapter [1] in the book _Beautiful Code_ in which Brian
Kernighan explains how to implement a regular expressions matcher using code
written by Rob Pike in C.

[1]:
[http://www.cs.princeton.edu/courses/archive/spr09/cos333/bea...](http://www.cs.princeton.edu/courses/archive/spr09/cos333/beautiful.html)

------
hyp0
see also parser combinator approach:

reg exp engine in 14 lines of python
[https://news.ycombinator.com/item?id=3202313](https://news.ycombinator.com/item?id=3202313)

------
zerr
Btw, is Scala still relevant with the coming of Java 9?

~~~
ARussell
I definitely think so. Why wouldn't it be? Do you think Java 8 or 9 would be
able to solve OP's problem with as much expressiveness as Scala?

~~~
zerr
Not completely, but there was/is a line of advising to use Scala as a better
Java. Java is getting better and better with subsequent versions, so at least
this line of Scala loses strength I believe.

~~~
seanmcdirmid
Scala is still a much better java than even Java 9. Even if you don't want to
go FP crazy, it still makes sense to at least try scala.

~~~
virtualwhys
Sean, you've written in the past that you tried Scala 7+ years ago; any reason
beyond working for M$ that you don't give it another look? It's certainly
improved a ton since your explorations during the stone ages of Scala ;-)

For example, you probably were never able to take advantage of type classes,
(G)ADTs, value classes, recursive types, exhaustive pattern matching, etc.,
etc. back in the day.

Would be nice to have an OO expert/advocate on the Scala side of the fence to
provide a counter point to the FP wave.

~~~
seanmcdirmid
I have nothing personally to write for the JVM...or I would use Scala. That's
what I meant by "better Java." Besides, the Scala community might not be a
great place for an OO advocate, Dart and Typescript, or maybe Swift, are more
of the future for us.

~~~
modersky
The Scala community is, and always has been, quite heterogenous. There's a
vocal, and sometimes quite abrasive group of fundamentalists on HN and
Twitter. But the Scala community is much more diverse than what you would hear
from them.

~~~
seanmcdirmid
There is a bit of difference between OO people who use Scala and OO people who
influence it (through implementation work or design input); I'm not seeing
much of the latter these days as an outsider, but I admit I might not be
looking hard enough.

------
bshimmin
The title is a little misleading - perhaps better would be "A very limited
subset of Regular Expressions in 100 lines of Scala".

While the code is concise, this is more a case of "it implements A and B of an
X" than "it implements an X, apart from A and B".

Still, all three parts of the series are a good read, and definitely helpful
for learning about parsing and about Scala.

~~~
peq
Regular expressions just need 3 things: sequence, alternatives (|), and
repetition(*). Everything else is an extension.

~~~
tel
And the empty versions/identities of those operations

~~~
harryjo
Right, those three things plus three times nothing. 3 + 3*0 = 3

