I know this will be a simple question. I am new coding and still have a lot to learn. I am running a movie API with node. As you know API's searches cannot have spaces " " and need a plus sign "+" in order to search a string. Example when I search Die Hard on the terminal it comes back as a movie called Die and does not recognize "Hard". If I search it as Die+Hard I will get the movie I am looking for. How do I add that plus sign without having the user write the plus sign in the search? Thank you for your help.
var axios = require("axios");
movieName = (process.argv[2]);
var queryUrl = "http://www.omdbapi.com/?t=" + movieName + "&y=&plot=short&apikey=...";
To replace all instances of a space in a string (let's call it str) with +:
str.replace(/ /g, "+");
To replace all instances of any whitespace characters with a +:
str.replace(/\s/g, "+");
For more information, see the MDN docs on String.prototype.replace().
var movieName = process.argv.slice(2).join("+");
this took care of it. Thank you for the help.
Related
I'm using a library nikaia/translation-sheet who basically pulls all the translations from the Laravel site into a google spreadsheet making it "easily" translatable with =GOOGLETRANSLATE(A1)
The problem comes with the parameters:
:price
:amount
:etc
So I've got the idea to substitute ":" with #nonmakingsenseworblablaprice so Google couldn't translate example:
=SUBSTITUTE(GOOGLETRANSLATE(SUBSTITUTE(B2;":";"#nonmakingsenseworblabla");"ES";"EU");"#nonmakingsenseworblabla";":")
Well, not sure why Google eats some letters and puts new ones:
:amount de saldo -> #nonmakingseseworblatamount of saldo
So I decided to do something like detect the parameter and change :amount to :a_m_o_u_n_t and that is apparently working and not being weirdly parsed converted or translated.
I was looking for a solution and found a similar idea but having problems migrating it to spreadsheets script plus is not detecting the parameter
Any one knows how to detect all :parameters in a sentence and put a symbol, slash, dash etc between the characters or letters? Example:
The amount :amount for this order number :order_id is :price
I've also tried regex but not been lucky so far
=REGEXREPLACE(GOOGLETRANSLATE(REGEXREPLACE(B22; ":(\w)([\w]+)"; "{%$1_$2%}"); "ES"; $C$1); "{%(\w)_([^_]+)%}"; ":$1$2")
There's a regex to select the spaces between letters, but good luck making that in excel or spreadsheets. Demo
Finally I've created a script to avoid parameters translation:
function translate(cell, lang) {
const content = cell.toString();
const keys = [];
const enc = content.replace(/:([\w_]+)/ig, function(m, param) {
const n = `[§${keys.length}]`;
keys.push(param);
return n;
});
return LanguageApp.translate(enc, "es", lang).replace(/\[§(\d+)\]/ig, function(m, param) {
return `:${keys[param]}`;
});
apparently template literals are not supported in the IDE (i get an illegal character warning when I enter the backtick). Is there an alternative? I have the following lengthy expression that I want to include as part of a restdb query:
"_created":{"$gt":{"$date":"$yesterday"}}"
Is there an alternative to painstakingly constructing this as a series of escapes and concatenations? This is what I have right now.
const dateexp = `"_created":{"$gt":{"$date":"$yesterday"}}"`
if (searchTerm) {
const regexterm = "\{\"\$regex\": "
const searchterm = searchTerm
var q1 = "{\"active\" : true, \"_tags\": " + regexterm + "\"" + searchterm + ", " + dateexp +
"\"}}"
console.log("q1 is", q1)
I found a trick that made this considerably easier -- I used the Rhino Online editor at jdoodle.com -- https://www.jdoodle.com/execute-rhino-online/
This sped up the trial & error considerably and I arrived at
var q2 = "{\"active\" : true, \"_tags\": " + regexterm + "\"" + searchterm + "\"\}, " + "\"_created\" : {\"\$gt\" : \{\"\$date\" :\"\$yesterday\"\}\}}"
A console editor in the Bixby IDE would be great!
PS - it helps to learn that in Rhino there is no console.log, but there is a print().
This doesn't help you right now, but the Bixby engineering team is hard at work on the "next generation" of javascript runtime environment for capsule code. I can't say much more than this, but rest assured that in the future, you will have a first-class, modern javascript development experience as a bixby capsule developer.
source: I work on the bixby developer tools team.
I am wondering is there any way to replace this type of value in string
https://farm5.staticflickr.com/4796/39790122335_bdc207b259_o.jpg https://farm5.staticflickr.com/4776/39790122225_c8e96339fa.jpg
What i want is that replace the right side of URL and just show the left side there is little space between them.
You can do that in many different ways, using many different languages.
For example, this is how you can do it with JavaScript
var str = 'https://farm5.staticflickr.com/4796/39790122335_bdc207b259_o.jpg https://farm5.staticflickr.com/4776/39790122225_c8e96339fa.jpg'
str = str.split(' ')
str = str[0]
it can be easily done using the split function.
First assign the url to a Variable
Python
theurl = 'https://farm5.staticflickr.com/4796/39790122335_bdc207b259_o.jpg https://farm5.staticflickr.com/4776/39790122225_c8e96339fa.jpg'
each_url = theurl.split()
now your new variable each url is a list of objects containing all the URLS
i.e each_url = ['https://farm5.staticflickr.com/4796/39790122335_bdc207b259_o.jpg ', 'https://farm5.staticflickr.com/4776/39790122225_c8e96339fa.jpg']
the Split function works in pretty different Programming Languages
though in some like Javascript you might have to specify split as split(' ')
showing you are splitting by spaces
I have this string:
194.44.176.116:8080
I want regex to take everything after the colon ':' but not take : itself. How do I do that?
This is something I did but it grabs numbers and the colon ':' which I don't want.
var portRe = /(?<=:)\d{2,5}$/gi;
I'm using this in NodeJs application.
Your regex to get everything between the : and the end would be:
/[^:]+$/
But as we know,that the port is a number, you can just check for the number at end of string:
/[0-9]+$/
Please note that this does not check if there is a : and so just returns the last digit. If you are sure that you have a string as you provided, those two are the easiest to understand minimalist solutions.
Otherwise refer to the other answers to do a lookahead/lookbehind or work with non capturing / capturing groups.
A general strategy here would be to just use a capture group to isolate what you really want to match:
/.*:(\d{2,5})/gi
Then access what you have captured in the first capture group.
var myString = "194.44.176.116:8080";
var myRegexp = /.*:(\d{2,5})/gi;
var match = myRegexp.exec(myString);
console.log(match[1]);
I would need some help. Basically I have a searchbar, in this searchbar I already have to preset a link that will lead to a specific search on google. The user in the search bar will write, for example, "dog" and will be brought directly to the search results on google gif. They own the http address that leads to search results. In the text below, replace the word "lolcats" with the word entered by the user in the searchbar taking into account the spaces that are recognized by% 20
I hope I'm well explained with this poor English
example link ("lolcats" Word to be replaced with the one that inserts the user into the searchbar)
https://www.google.it/search?as_st=y&tbm=isch&hl=it&as_q=lolcats&as_epq=&as_oq=&as_eq=&cr=&as_sitesearch=&safe=images&tbs=itp:animated,ift:gif#imgrc=_
try to create your url string like this:
var keyWord : String // which you get from user
let part1 = "https://www.google.it/search?as_st=y&tbm=isch&hl=it&as_q="
let part2 = "&as_epq=&as_oq=&as_eq=&cr=&as_sitesearch=&safe=images&tbs=itp:animated,ift:gif#imgrc=_"
var encodedKeyWord = keyWord.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)
var finalUrlString = part1 + "\(encodedKeyWord)" + part2
hope it works :S