How to remove ALL numbers from a cell with a function or regex?

前端 未结 3 1648
逝去的感伤
逝去的感伤 2021-02-10 17:30

I have cells that look like this, one per line:

Duffy,John: \'Heritage: Civilization and the Jews\'- Fanfare & Chorale,Symphonic Dances + Orchestr

3条回答
  •  说谎
    说谎 (楼主)
    2021-02-10 18:13

    I was faced with a similar problem, but went another way, wanting to avoid using vba. A recursive use of substitute did the trick for me, as illustrated below:

    Original data (in A1:An, n=integer) ROE -1.00 P/E 0.07 -0.85 ROC-ROE 0.02 -0.03 etc..

    =SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A1,"1",""),"0",""),"2",""),"3",""),"4",""),"5",""),"6",""),"7",""),"8",""),"9","")

    which can be extended to get rid of "-" and the decimal indicator "." as well as "+" (if relevant) and finally, superfluous spaces using

    =trim(substitute(substitute(substitue(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A1,"1",""),"0",""),"2",""),"3",""),"4",""),"5",""),"6",""),"7",""),"8",""),"9",""),"-",""),"+","")," .",""))

    where the lowercase represents complications added in the current step.

    This maps naturally onto the entire array by changing the range reference to the entire array to be parsed (A1:An) and entering the formula as an array (i.e., using Ctl+Enter instead of Enter to complete the task).

    I then use len(B1) to check the results are what I want.

    Not elegant, admittedly. But may be a useful exercise for teaching students to think and code "on the fly."

提交回复
热议问题