So if it does work (I can't see why not), do the following changes:
* remove `var length: it's unused in either case
* `var branchRegex...` -> `static const BRANCH_REGEX = const RegExp(BRANCH_PATTERN)` and make it a class property.