Home > Mobile >  Google sheets - Replace quotation marks " " with the greek ones « » in a text
Google sheets - Replace quotation marks " " with the greek ones « » in a text

Time:11-19

I want a function that can replace ANY " " with the ones that we use in greece « ».

For example in A2 i have:

The kid said "lets play" and i said "yes!".

And i want a function that will return:

The kid said «Lets play» and i said «yes!».

(If you dont know where the greek quotation marks are located in the keyboard, then simply copy paste them and insert them in your function: « » )

Thank you!

CodePudding user response:

try:

=REGEXREPLACE(A1, """(.*?)""", "«$1»")

enter image description here

CodePudding user response:

What worked for me:

=REGEXREPLACE(A1,CHAR(34)&"(.*?)"&CHAR(34),"«$1»")

enter image description here

CodePudding user response:

As an alternative to the Sheets formulae already provided, you can also make use of Apps Script:

function replaceQM() {
  let ss = SpreadsheetApp.getActiveSheet();
  let cell = ss.getRange('A1').getValue().toString();
  cell = cell.replace(/"(?=[\w,.?!\)]|$)/g, "«").replace(/(?<=[\w,.?!\)]|^)"/g, "»");  ss.getRange('A2').setValue(cell);
  console.log(cell)
}

The snippet above makes use of regex in order to replace the quotation marks. The first replace method is used to find any quotation marks at the beginning of a word and the second replace is used to find any quotation marks at the end of a word, taking into account the punctuation marks.

Therefore, if we run the script above, we'll be getting the following results:

after running the script

Reference

  • Related