JodaOrg/joda-time — pull request #169 by gswierczynski (2014-08-23 10:53:54+00:00)
Title: Assure correct order of regex affixes during parsing.

During investigation of issue [#154](https://github.com/JodaOrg/joda-time/issues/154) I have discovered that the reg ex implementation will fail in following scenario:
```java
public void testRegExAffixParseOrder() {
PeriodFormatter f = new PeriodFormatterBuilder().appendDays()
.appendSuffix(new String[]{"^1$","[0-9]*"}, new String[]{"day", "days"})
.toFormatter();
String twoDays = Period.days(2).toString(f);
f.parsePeriod(twoDays);
}
```
with following exception:
```java
java.lang.IllegalArgumentException: Invalid format: "2days" is malformed at "s"
at org.joda.time.format.PeriodFormatter.parseMutablePeriod(PeriodFormatter.java:326)
at org.joda.time.format.PeriodFormatter.parsePeriod(PeriodFormatter.java:304)
at (...)
```
This will happen because the "day" word will be matched first even though the string contains "days".
For the same reason the PluralAffix is swapping the singular and plural in parse method if the latter is longer.

This pull request solves that issue by storing sorted array of suffixes that will be used by the parse method.
Added tests for regex affix and for plural affix (this scenario was not covered in tests).