You have an extra space in front of the `if`, misaligning the indentation.    The regexp looks scary like this (nested repeat operators can easily create exponential running time). Why not just replace the `\\w` with `[\\w$#]`?