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!
try:
=REGEXREPLACE(A1, """(.*?)""", "«$1»")
What worked for me:
=REGEXREPLACE(A1,CHAR(34)&"(.*?)"&CHAR(34),"«$1»")
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:
Reference
Google Apps Script;
String.prototype.replace();
Regex.
Related
I am tryng to get rid of shortcodes inside a Google Sheet column. I have many items such as [spacer type="1" height="20"][spacer] or [FinalTilesGallery id="37"] I just would like to cancel them. Is there any simple way to do it?
Thanks !
For in-place replacement, the quick option would be to use the Find and Replace dialog (Ctrl + H) with Search Using Regular Expressions turned on, which is more powerful than your standard Find and Replace.
Find: \[.*?\] - Match anything within an open-bracket up to the very next close-bracket. This should work assuming you have no nested brackets, e.g. [[no][no]].
If you do have nested brackets, you'll have to change this to \[[^\[\]]*\]. And continue to Replace All until all the codes are gone.
Replace: Nothing.
Replace All. If you don't want to affect other sheets that may be in your document, make sure you select the right range to work with, too.
This just erases everything within the brackets.
If you want to erase any redundant spaces left by this, simply Find and Replace again (with Regular Expressions) on + (space and plus), which will match 1 or more spaces and replace with (single space).
E.g.:
string [] [] string2 -> string string2 after the shortcode replacement.
After replacing spaces, it will become string string2.
Let's say your original strings are in the range A2:A. Place the following into B2 of an otherwise completely empty Column B (or the second cell of any other empty column):
=ArrayFormula(IF(A2:A="",,TRIM(REGEXREPLACE(A2:A,"\[[^\[\]]+\]",""))))
I can't see your data, so I don't know what kind of information is between these shortcodes. If you find that this leaves you with concatenated pieces of data where there should be spaces between them, replace the above with this version:
=ArrayFormula(IF(A2:A="",,TRIM(REGEXREPLACE(SUBSTITUTE(SUBSTITUTE(A2:A,"["," ["),"]","] "),"\[[^\[\]]+\]",""))))
I can't teach regular expression language here. But I will note that, since square brackets have specific meaning within regex, your literal square brackets must be indicated with the escape character: the backslash.
Here is the regex expression alone:
\[[^\[\]]+\]
The opening \[ and the closing \], then, reference your actual opening and closing bracket sets. If we remove those, we have this left:
[^\[\]]+
Again, you see the escaped opening and closing square brackets, which I'll replace with the word these:
[^these]+
What remains there are opening and closing brackets with regex meaning, i.e., "anything in this group." And the circumflex symbol ^ as the first character within this set of square brackets means "anything except." The + symbol means "in any string length of one or more characters."
So that whole regex expression then reads: "A literal open square bracket, followed by one or more characters that are anything except square brackets, ending with a literal closing square bracket."
And we are REGEXREPLACE-ing any instance of that with "" (i.e., nothing).
I want to add comma in spread sheet as a superscript like :
in this ->> ¹,²
comma is not as superscript. Is there any way out for comma to be added as superscript in google spreadsheet?
For 1 and 2 and many others, there is a function available in sheet like =char(178)
however I am ot able to find the code for comma.
Answer:
As there is no Unicode for a superscript comma, you can not do this.
More Information:
Not all characters have superscript-versions set in unicode. You can see the full list of available superscript characters here.
You can either use the dot operator (U+2265) ⋅, or the modifier letter apostrophe (U+02BC) ʼ as separators instead, if you wish to hard code this. I am of the personal opintion that the dot operator looks more like a comma, but they both appear as below:
¹⋅² (dot operator)
¹ʼ² (modifier letter apostrophe)
As Google Sheets isn't a word processing application, there is no direct in-built way to make text appear as superscript, akin to <sup>1,2</sup> in HTML:
1,2
References:
Unicode subscripts and superscripts - Wikipedia
I am working on a project, in which you type your input sentence, and I need to be able to use " and ' in the sentence, such as Input = "I said, "Hi what's up?" print(Input) in which I get an error. If anyone knows how to fix this that would be great.
See https://www.lua.org/pil/2.4.html. Lua has very interesting feature to declare string with square brackets:
input = [[I said, "Hi what's up?"]]
input = "I said, \"Hi what's up?\""
input = 'I said, "Hi what\'s up?"'
I will tell some things in addition to what #Darius told above
When you tried to add a quatation mark inside a string, the lua interpreter get confused and break your string after the next quation mark without reaching the end of the line. That's the reason for the error.
Try to understand it by the following code
str = "Hello I"m somebody" -- here the interpreter will think str equals to "Hello I" at first, and then it will find some random characters after which may make it confused (as m somebody is neither a variable nor a keyword)"
-- you can also see the way it got confused by looking at the highlighted code
--What you can do to avoid this is escaping the quotes
str = "Hello I\"m somebody" -- here the interpreter will treat \" as a raw character (") and parse the rest.
You can also use the escape character () with others such as \', \", \[, \n (newline character), \t (tab) and so on.
(Sorry for my broken English)
I'm trying to match an or in a string and if it is not enclosed in single quotes and replace it with a minus sign (-).
For example:
local input1 = "'condition1' or 'condition2'"
input1:gsub(pattern, "-") --> Should return "'condition1' - 'condition2'"
local input2 = "'condition1 or condition2'" -- Note the position of the '
input2:gsub(pattern, "-") --> Should return "'condition1 or condition2'"
Where pattern is the Lua pattern I am asking for.
Im sure that I have to use %b'' in order to detect if the or is quoted, so I tried this as my pattern: [^%b'']or
But that doesn't work for me.
Please note that I can use only pure Lua libraries (so no LPeg) as the code will be runned in different Lua runtimes (all 5.2) not supporting C libraries.
And please note that this question is not a duplicate - there is no question asking how to do this in Lua with its own patterns.
Try input:gsub("('.-'.-)or","%1-").
This assumes that or always appears after a quoted string. It captures everything from the quoted string until just before or and replaces this with the captured text followed by -, as required.
Could anybody help me make a proper regular expression from a bunch of text in Ruby. I tried a lot but I don't know how to handle variable length titles.
The string will be of format <sometext>title:"<actual_title>"<sometext>. I want to extract actual_title from this string.
I tried /title:"."/ but it doesnt find any matches as it expects a closing quotation after one variable from opening quotation. I couldn't figure how to make it check for variable length of string. Any help is appreciated. Thanks.
. matches any single character. Putting + after a character will match one or more of those characters. So .+ will match one or more characters of any sort. Also, you should put a question mark after it so that it matches the first closing-quotation mark it comes across. So:
/title:"(.+?)"/
The parentheses are necessary if you want to extract the title text that it matched out of there.
/title:"([^"]*)"/
The parentheses create a capturing group. Inside is first a character class. The ^ means it's negated, so it matches any character that's not a ". The * means 0 or more. You can change it to one or more by using + instead of *.
I like /title:"(.+?)"/ because of it's use of lazy matching to stop the .+ consuming all text until the last " on the line is found.
It won't work if the string wraps lines or includes escaped quotes.
In programming languages where you want to be able to include the string deliminator inside a string you usually provide an 'escape' character or sequence.
If your escape character was \ then you could write something like this...
/title:"((?:\\"|[^"])+)"/
This is a railroad diagram. Railroad diagrams show you what order things are parsed... imagine you are a train starting at the left. You consume title:" then \" if you can.. if you can't then you consume not a ". The > means this path is preferred... so you try to loop... if you can't you have to consume a '"' to finish.
I made this with https://regexper.com/#%2Ftitle%3A%22((%3F%3A%5C%5C%22%7C%5B%5E%22%5D)%2B)%22%2F
but there is now a plugin for Atom text editor too that does this.