Westinghouse Electric Corp. said yesterday it plans to "enhance stockholder value" by selling its Group W Cable television business, the nation's third-largest cable operator, and repurchasing up to 25 million shares of its common stock.

Westinghouse stock soared 4 3/4 to 38 1/4 in response to the surprise announcement, as nearly 3.9 million shares changed hands. The sale of Group W, which operates in major markets including Manhattan, would be the largest in cable history, with an anticipated price in excess of $2 billion. Group W operates 140 cable systems with 2.1 million subscribers.

Westinghouse said it hopes to complete the sale of the cable television business in 1986. The company said it will stay in the broadcasting business, retaining radio and television stations including WJZ-TV, Channel 13, in Baltimore and certain other properties including Home Team Sports, which carries local sporting events via cable to subscribers in the Baltimore-Washington area.

"I imagine the chances are that someone inside the industry will be the buyer," said Westinghouse broadcasting division Chairman Dan Ritchie. "I think there will be a lot of interest, since this is the largest chunk that has ever come on the market. We have peeled off 350,000 subscribers recently, and what is left is the prime stuff. We have things like Beverly Hills and Westwood, Calif., the upper half of Manhattan and Palm Beach."

Ritchie said Westinghouse was getting out of cable television because the stock market values the company on the basis of reported earnings, rather than cash flow. He said that even though Westinghouse's cable business is a strong cash producer, high non-cash expenses such as depreciation depress earnings and pull down the price of Westinghouse stock.

Broadcasting analysts said another reason Westinghouse is getting out of the business is that cable growth has slowed, which means the business is entering a more mature phase that will require additional management expertise and marketing savvy to maintain profitability.

"Cable and broadcasting is difficult for Westinghouse to digest because they are used to running different kinds of businesses," said Charles H. Kadlec, a broadcasting industry consultant. "Also, revenue growth in the industry has gone from 40 percent to 20 percent today, with projections of 10 to 15 percent over the next four or five years.

"On the other hand, there are legislative and regulatory changes that will deregulate cable rates and give cable operators more power."

Westinghouse said it will begin to purchase up to 25 million of its own shares in open-market purchases or through private transactions at prices management deems appropriate. The purchases will initially be financed with existing cash, internally generated funds and short-term debt.

The company said it plans to retire the short-term debt in 1986, using proceeds from the sale of its cable television business and other unspecified asset sales. Westinghouse said it has retained First Boston Corp. and Shearson Lehman Bros. as financial advisers in connection with the restructuring.

Westinghouse Chairman Douglas D. Danforth said, "Our consideration of the sale of Group W Cable in no way dampens our enthusiasm for the commercial broadcasting business. We are proven leaders in this industry, and our broadcasting operations continue to make significant contributions."

Westinghouse Broadcasting and Cable includes 12 AM and FM radio stations, five television stations and the cable operations. The division had revenue of $985 million and an operating profit of $71.2 million in 1984, versus revenue of $852.4 million and an operating profit of $47.8 million in 1983.