You're trying to negate a character group of either a word or digit to come immediately after "func" with [^\w\d]*, a whitespace qualifies.
You also specify any number of non-words and non-digits with the *, explaining the several whitespaces captured alongside "func".
I hope that answers your question as to why you're capturing the whitespaces.
I am uncertain what your exact goal is, so here are some examples:
This statement matches only "func" with any word immediately after it: \A(?:(func)[\w\d]*|(func)\z)
This statement matches "func" at the beginning of EACH line and the end of the ENTIRE string: ^func|func\z
This statement matches "func" at the beginning of the entire string and the end of the ENTIRE string: \Afunc|func\z
You can find a quick reference page here: Regular Expression Language - Quick Reference
func, else it won't match inputs likefunc sum(a, b)