Nowadays, and specifically if you are handling gTLDs, you should use RDAP and not whois anymore. Far easier to parse, because the result is JSON not free form unstructured text. Not all registrars or registries, even in gTLDs, and even if mandated by ICANN since this August 26th, may have working and properly following standards RDAP servers, but they should and the number can only increase.
See https://about.rdap.org/ for a primer, or ICANN documentation: https://www.icann.org/rdap
Otherwise, a quick example:
$ wget -qO - https://rdap.verisign.com/com/v1/domain/godaddy.com | jq '.events[] | select(.eventAction | contains("expiration")) | .eventDate'
"2021-11-01T11:59:59Z"
$ wget -qO - https://rdap.verisign.com/com/v1/domain/godaddy.com | jq '.entities[0].vcardArray[1][1][3]'
"GoDaddy.com, LLC"
$ wget -qO - https://rdap.verisign.com/com/v1/domain/godaddy.com | jq '.links[1].href'
"https://rdap.godaddy.com/v1/domain/GODADDY.COM"
$ wget -qO - https://rdap.godaddy.com/v1/domain/GODADDY.COM | jq '.events[] | select(.eventAction | contains("expiration")) | .eventDate'
"2021-11-01T06:59:59Z"
(but of course in real code you shouldn't hardcode position in arrays and things like that, you need to properly parse the JSON output).