Optimised regexp matching and added trimming to fix #3
Added tests.
Updated gradle ignores in .gitignore