SAN FRANCISCO — In a recent speech to Republican donors, John Cox, a candidate for California governor, exuded the kind of optimism that could only come from an underdog.

“Republicans can win in California,” he said, repeating the line twice during his speech.

But getting GOP benefactors to believe that won’t be easy. The electoral math — the 19-point advantage Democrats enjoy among registered voters — suggests the odds are long for any GOP contender hoping to succeed Jerry Brown as governor. Meg Whitman, a Silicon Valley executive, famously spent more than $144 million of her own money but lost to Brown by 13 points in 2010, a year when Republicans cleaned the clocks of Democrats across most of the country.

As Democratic donors shower front-runner Gavin Newsom and other leading Democrats with campaign cash, Republican counterparts could be more hesitant to deliver the dollars that GOP candidates need for a fighting chance.

“The trouble for the Republicans is practically nobody thinks they have a chance of winning,” said Jack Pitney, a political expert at Claremont McKenna College. “Fundraising is going to be a huge problem because people don’t want to send money to a sure loser.”

Still, the top Republican candidates in the race so far — Cox, a San Diego County real estate investor who has not held elected office, and state Assemblyman Travis Allen, a conservative from Huntington Beach who often attacks the Democratic agenda from the Assembly floor — insist that they see a clear path to the governor’s mansion.

With Brown terming out, Cox pointed out, the candidates for governor aren’t competing with an incumbent. And even dubious political observers note that in today’s topsy-turvy poltical world, nothing is certain.

“Things can change in California,” said Bill Whalen, a longtime GOP strategist now at Stanford’s Hoover Institution. “What does it take to get Republicans back in the game in California? One thing that could help is Democrats committing penalties.”

One example of such a “penalty,” Whalen said, would be passing a highly controversial law that inspires a referendum to overturn it — which could bring conservative voters to the polls in greater numbers.

The California Republican Party, which gave the 2014 GOP candidate, former Treasury Department official Neel Kashkari, zero financial help for his run against Brown, promises to pony up some cash for the governor’s race this time around.

“I believe that we will have a Republican in the top two following the June primary, and that is critical,” said California GOP Chairman Jim Brulte.

But, he added, it also is vital for the GOP to hold onto — and gain — congressional and legislative seats.

“The prudent thing is for the party to focus on legislative and congressional races,” said Kevin Spillane, a veteran GOP strategist. “To influence statewide races costs a huge amount of money. The question is: What will Republican donors do? Where will they focus their money?”

Under California’s “top two” primary system, which took effect in 2011, it’s no longer a given that a Republican candidate will even make it onto the November 2018 general election ballot. The two candidates who win the most votes in the June primary — regardless of their party — advance to the general election.

In the 2016 U.S. Senate race, myriad Republican candidates splintered the vote, leaving two Democrats in the general election.

That’s something GOP leaders are hoping to avoid in next year’s governor’s race. Under a bylaw change proposed by Republican National Committeewoman Harmeet Dhillon, the state party would be able to nominate a candidate for governor — as well as other statewide offices — before the June primary. Such a move, Dhillon said, would help Republican voters and donors unite around one candidate.

“We saw a spectacle of 17 people running for Senate in the last election cycle, and we don’t wish to encourage that,” said Dhillon, a San Francisco attorney.

A May poll conducted by UC Berkeley’s Institute of Governmental Studies — taken before Allen entered the race and before former GOP assemblyman David Hadley dropped out — showed Cox trailing Newsom and former Los Angeles Mayor Antonio Villaraigosa with 9 percent of the vote. But a poll conducted for the Cox campaign in late July showed him in second place after Newsom with 14.1 percent, and Allen at 9.6 percent.

Political strategists are quick to point out that the field is not necessarily set for either party. They note that the filing deadline is still six months away, and a well-known politician or celebrity could jump into the race, shaking it up, while others could bow out, leading their supporters to redistribute themselves among the remaining candidates.

But for now, Republican voters are sizing up two small-government conservatives. Allen is a lifelong Californian who made news when he launched a ballot initiative to repeal the gas tax the Legislature passed in April. Cox is a relative newcomer to California who has poured $3 million of his own money into the race.

In an interview, Cox said that he won’t provide more funds to his campaign — “not unless I want a divorce.”

“I’m counting on the people of California to come up with a decent chunk and at least match me,” he said. “I’m not Meg Whitman. I’m not a billionaire.”

At the recent gathering of about 150 Republicans at the Far East Cafe in San Francisco’s Chinatown, donors snacked on dumplings and lychee as Cox went table-to-table introducing himself, patting backs and talking about how America was “the greatest country in the world.”

Republicans at the dinner who had heard both candidates said it was clear that Cox was a newbie politician. Listening to him give a speech earlier this year was “sort of torturous,” said Paul Cummings, a former chairman of the Alameda County GOP. But, he said, like most greenhorn candidates, Cox had improved since then.

In his speech that night, Cox pointed out that 19 states around the country have elected businessmen as governors. In Maryland, he said, registered Democrats outnumber registered Republicans nearly two-to-one — a bigger disadvantage than in California — but the state elected a Republican governor, Larry Hogan, in 2014. “How about we make California number 20?” he asked, triggering a round of applause.

But some of his jokes fell flat, like his observation that being chairman of Chicago’s Cook County Republican Party a decade ago was like being the “opposition leader to Saddam Hussein.” And then there was his quip that Gov. Brown started his speeches by saying, “Hello, fellow freeloaders!”

Both candidates will appeal to California voters who feel the state has become unaffordable for many in the middle class. Allen, a certified financial planner and avid surfer, talks about family and friends who have scattered to other states because of California’s high cost of living and tax burden. He also paints a grim picture of failing schools and dangerous streets.

“These are all very fixable problems,” Allen said. “My campaign is targeted directly at the hardworking Californians who have been marginalized by the elitist, big-government policies coming out of Sacramento and San Francisco.”

Allen, who vows to cut taxes if elected, failed to pay $42,000 in 2012 and 2013 federal income taxes until the Internal Revenue Service placed a tax lien on him this year, this news organization reported last week. His campaign blamed an incorrect mailing address.

Cox often refers to his single mother, a public schoolteacher in Chicago, who “always talked about California as the Golden State of her dreams.” After moving west in 2008, Cox said, “I discovered when I got here that the Golden State wasn’t quite golden anymore and was in fact more corrupt than my home state of Illinois.”

Allen did not accept an invitation to the San Francisco fundraiser. He said he had a meeting that night with Riverside business owners. But he arguably needs the money. He had about $78,000 to spend as of June 30, according to campaign finance disclosure reports he filed with the state, compared with Cox’s $2.8 million.

Most of the Republicans interviewed at the San Francisco dinner said they had no real opinion about their party’s two candidates for governor.

“There is no way a Republican will ever gain enough votes to be in that top two,” unless there’s a large Democratic field or a big scandal hits the Democratic nominee, said one Republican donor who asked not to be named because she wanted to give a candid assessment of the race. “I hate to be pessimistic, but I think we will end up with two Democrats” in the general election.

The governor’s race, she said, is a “lost cause.”

JOHN H. COX

Age: 62

Family: Wife, Sarah, and four adult daughters.

Hometown: Born and grew up in Chicago, moved to San Diego in 2008 and has lived in the state full-time since 2011.

Education: Law degree from Illinois Institute of Technology; B.A. from the University of Illinois at Chicago.

Occupation: Real estate investor, lawyer and CPA.

Political history: Ran unsuccessfully for elected office several times in Illinois, including in the 2004 U.S. Senate race won by Barack Obama, and a short-lived 2008 bid for president.

Fun fact: Worked his way through college as a tennis teacher.

Quote: “I’ll plead guilty to being boring.” Politics these days, he lamented, is “not about character — you saw that in the last presidential race. It’s about reality television. It’s about who has the best slogans, who can whip up the crowd the most. I’m not about that. I’m about sober reflection, about policy discussions.”

TRAVIS ALLEN

Age: 43

Family: Wife, Arielle, and 8-year-old daughter Charlotte. New baby due in November.

Hometown: Born in San Diego, raised in Chula Vista, now in Huntington Beach.

Education: Cal State Los Angeles, Cal State Long beach, BA in economics.

Occupation: State assemblyman, certified financial planner.

Political history: Elected to California Assembly in 2012.

Fun fact: One of 66 people who set a Guinness World Record in 2015 for most riders on a surf board at once.

Quote: “There is a silent supermajority in California that has been forgotten and marginalized by Jerry Brown and the California Democrats.”