made some edits to shorten the code, also implements match(regex) instead of scan(regex)