Refactored search regexes and if statements

The `if` statements are now in ternary form, which should increase speed
a bit. I also cleaned up the regexes a bit to be more robust. Further
testing will have to prove if anu future changes need to be made.