How to retain '\s' in Google App Script regex

34 views
Skip to first unread message

Tom Hall

unread,
Jun 28, 2023, 8:50:02 AM6/28/23
to Google Apps Script Community

I am currently populating a boilerplate formula in a Google Sheet after moving the rest of the data to another sheet, however the formula seems to drop the '' from '\s' in the sheet,leading to the regex detecting and replacing all S's rather than whitespace.

e.g. REGEXREPLACE(A2,"\s","") becomes REGEXREPLACE(A2,"s","")

The full code is:

descriptionSheet.appendRow(['Brand', 'Product Type', 'Product Name', 'Size', 'Colour', 'Condition', '', '=VLOOKUP(D2&" "&A2&" "&B2,Measurements!A:C,2,FALSE)', '=VLOOKUP(D2&" "&A2&" "&B2,Measurements!A:C,3,FALSE)', '=A2&" "&IF(C2="","",C2&" ")&B2&"\n\n"&D2&"\n"&E2&"\n\n"&F2&" condition - "&IF(G2="","No rips, holes or stains!",G2)&"\n\nMeasurements\n⦿ Pit to pit: "&H2&" inch\n⦿ Shoulder hem to bottom: "&I2&" inch\n\nVerified Depop Top Seller! Shop with confidence.\n\nFree Shipping on bundles.\nSame day dispatch on request.\n\n#"&REGEXREPLACE(A2,"\s","")&" #"&REGEXREPLACE(A2&B2,"-|\s","")&" #"&REGEXREPLACE(K2,"-|\s","")', '=CONCATENATE(A2," ",B2," ",C2)', '=REGEXREPLACE(A2,"[^A-ZÀ-Ö]","")&"-"&REGEXREPLACE(K2,"[^A-Z0-9]","")&"-"&D2&"-"&SUBSTITUTE(UPPER(JOIN("",ArrayFormula(left(split(F2," "),1)))),"-","")&"-"&UPPER(LEFT(E2,3))' ]);

Note the \n is working as desired. Only the \s is causing an issue.

Tried using String.raw and changing code to use /\s/g instead of just \s

Tom Hall

unread,
Jun 28, 2023, 11:16:48 AM6/28/23
to Google Apps Script Community
This is solved. I need to use \\s instead of just \s.
Reply all
Reply to author
Forward
0 new messages