Search code examples
regexgoogle-sheetsgoogle-sheets-formula

finding full stops in google sheet cell strings, excluding file extensions eg .xlsx


Im attempting to migrate from Google Drive to Microsoft OneDrive and the migration continually fails due to invalid characters such as ~ " # % & * : < > ? / \ { | }.

I've removed all instances of the above characters from the files/folders and it is still failing.
I believe it is due to full stops in the middle of file/folder names an example is below:

Acuse.GASP8409257P9.6.2021.pdf

Basically I would want to find all instances of full stops in the middle of the file names, while excluding just files that have file extensions such as .docx

Would a regex do the job here? I've attempted to find one online, but to no avail, any help is appreciated.

I've attempted to use a regex to find the full stops but nothing is working as I would like.


Solution

  • UPDATE
    (following OP's comment): "...how to replace the full stops with underscores _ instead"

    =SUBSTITUTE(REGEXREPLACE(A2,"\D+$|[^a-zA-Z0-9\.]",""),".","_")
                     &REGEXEXTRACT(A2,"\D+$")
    

    result: Acuse_GASP8409257P9_6_2021.pdf


    Original reply

    Please try the following

    =REGEXREPLACE(A2,"(\W)|(.\D+$)","$2")
    

    OR

    =REGEXREPLACE(A2,"\D+$|\W","")
          &REGEXEXTRACT(A2,"\D+$")
    

    (Do adjust the formula according to your ranges and locale)

    enter image description here