Many investors who pulled money out of the stock market in the last year now regret their decision.

Some 38% of investors said they sold stocks last year due to a current event, according to a study from MagnifyMoney. Of that group, 40% said they wish they'd kept their money invested. The online survey of more than 1,000 U.S. consumers was conducted April 15 to 20.

The survey found that younger investors were more likely to panic-sell. Nearly 70% of Gen Z investors pulled money from the market along with 57% of millennials. At the same time, 49% of men sold stocks due to a negative event, compared to 24% of women.

"Time is the ultimate weapon when it comes to investing," said Matt Schulz, chief credit analyst at LendingTree. "It gives younger investors a huge advantage over their older counterparts.

More from Invest in You:
Choosing a health plan that fits your budget and life
3 ways retirees can better cope with inflation
How to buy more than $10K in government I bonds

"Unfortunately, however, Gen Z and millennials risk squandering that advantage if they pull their money out of the market when times get tough."

The best move for young investors is to stay focused on the future and leave their money where it is, Schulz said.

"Ride the wave and trust that better times are ahead, because history has shown that when it comes to the stock market, they almost always are," he said.

Different events spook investors more

Certain current events have sparked more worry from investors, the survey found. Overall, inflation topped the chart as the item that has most unnerved U.S. consumers in the last year.

Americans are also worried about the coronavirus pandemic, economic policy and the war between Russia and Ukraine.

Click to show more

Emergency savings and how much money people are willing to invest were the most hit by current events in the last year, according to the survey. People also rethought their living situations as housing prices surged, and are revising the level of risk they're willing to take in investing.

How to avoid regret

To shield yourself from too much investing regret, experts generally recommend starting as soon as possible and coming up with a plan for your money to grow it over time.

"You want to start as soon as you can," said Shelly-Ann Eweka, senior director of financial planning strategy at TIAA. This is because with more time, you'll reap greater benefits from compounding, which is the interest earned on your invested money.

Some people may put off investing to prioritize other financial goals, which Eweka cautions against.  

"You really should be trying to manage all of your financial goals at once," she said, adding that if you put off investing, you're missing out on years of compounding growth. "That's why it's important to work with someone."

Enlisting the help of a financial professional can make this process a lot easier, said Eweka.

SIGN UP: Money 101 is an 8-week learning course to financial freedom, delivered weekly to your inbox. For the Spanish version Dinero 101, click here.

CHECK OUT: 74-year-old retiree is now a model: 'You don't have to fade into the background' with Acorns+CNBC

Disclosure: NBCUniversal and Comcast Ventures are investors in Acorns.