Implement `String#to_cents`, which should parse prices expressed as `$1.23` and return number of cents, or in case of bad format return `nil`.

Source: codewars | Difficulty: EASY
Tags: Fundamentals

Starter code: def to_cents(amount):
	

Solutions:
import re

def to_cents(amount):
	m = re.match('\\$(\\d+)\\.(\\d\\d)\\Z', amount)
	return int(m.expand('\\1\\2')) if m else None


from re import compile, match
REGEX = compile('\\$(?P<integer>\\d+)\\.(?P<frac>\\d{0,2})$')

def to_cents(amount):
	m = match(REGEX, amount)
	if m and m.group(0) == amount:
		return int(m.group('integer')) * 100 + int(m.group('frac'))


def to_cents(amount):
	if amount and amount[0] == '$':
		try:
			return int(amount[1:-3] + amount[-2:])
		except:
			return None
	return None


import re

def to_cents(amount):
	matched = re.search('\\A\\$(\\d+).(\\d{2})\\Z', amount)
	if matched:
		return int('{}{}'.format(*matched.groups()))


from re import match

def to_cents(amount):
	res = match('^\\$(\\d*)\\.(\\d{2})(?!\n)$', amount)
	return int(''.join(res.groups())) if res else None


import re

def to_cents(amount):
	return int(re.sub('\\$|\\.', '', amount)) if re.search('^\\$\\d+\\.\\d{1,2}\\Z', amount) else None


import re

def to_cents(amount):
	return int(re.sub('\\D', '', amount)) if re.match('\\$\\d*\\.\\d{2}\\Z', amount) else None


import re

def to_cents(amount):
	if not re.match('^\\$(0|[1-9]+\\d*)\\.\\d{2}\\Z', amount):
		return None
	return int(re.sub('[\\$\\.]', '', amount))


import re

def to_cents(amount):
	pattern = re.compile('^\\$([\\d]+)\\.([\\d]{2})$')
	if re.fullmatch(pattern, amount) == None:
		return None
	price = re.fullmatch(pattern, amount)
	return int(price.group(1)) * 100 + int(price.group(2))