Sorting Blocks of Text

Sorting lines of text is easy. Many text editors include that functionality built in. But, what if you need to sort blocks of text, e.g. a PHP classes. Here are some ways to do it.

1. Convert each block of text to a single line by replacing each line break with a unique identifier. Run your built-in line sorting function. Replace each unique identifier with a line break again.

2. Write a regular expression that will match each block of text and sort using a regular expression.