Question: I need a utility which allows me to do a diff and print each side on a separate sheet of paper. I've so far looked at WinMerge, ExamDiff Pro, Compare It, and SmartSVN's utility, and all of them allow the printing of diff results, but they put both sides on one sheet.

Essentially our formatting rules allow 120 character horizontal widths, and the word wrapping is making the printouts less effective. We can lower the font size, but then it's hard to read.

Free is better, but commercial will do. Syntax highlighting for Java is a plus.

**Edit:** Bonus points for a Win app, though I'll take nix app suggestions as backups

Answer: 
Unless you're doing this for the challenge, have a look at [Google Code Prettify](http://code.google.com/p/google-code-prettify/).

For your problem, you could read up on [parsing (and lexers) at Wikipedia](http://en.wikipedia.org/wiki/Parsing). It's a huge topic and you'll find that you'll come upon bigger problems than parsing strings.

To start, you *could* use regular expressions (although they rarely have the accuracy of a true lexer.) A typical regular expression for matching a string is:

```
/"(?:[^"\\]+|\\.)*"/

```

And then the same for `'` instead of `"`.

Otherwise, for a character-by-character parser, you would set some kind of state that you're in a string once you hit `"`, then when you hit `"` that is not preceded by an uneven amount of backslashes (an even amount of backslashes would escape eachother), you exit the string.
You can find quotes using regular expressions but if you're writing a syntax highlighter then the only reliable way is to step through the code, character by character, and decide what to do from there.

E.g. of a Regex

```
/("|')((?:\\\1|.)+?)\1/g

```

(matches "this" and 'this' and "thi\"s")