I Have these regex for different country's,
var ukM = /(070|071|072|073|074|075|076|077|078|079)\d{7,8}$/;
var ireM = /(083|085|086|087|089)\d{7,8}$/;
var ireL = /(01|021|022|023|024|025|026|027|028|029|0402|0404|041|042|043|044|045|046|047|049|0504|0505|051|052|053|056|057|058|059|061|062|063|064|065|066|067|068|069|071|074|090|091|093|094|095|096|097|098|099)\d{7,8}$/;
var usaM = /(713|071|072|073|074|075|076|077|078|079)\d{7,8}$/;
var usaL = /(201|202|203|204|205|206|207|208|209|210|211|212|213|214|215|216|217|218|219|224|225|226|227|228|229|231|234|236|239|210|211|212|213|214|215|216|217|218|219|224|)\d{7,8}$/;
Is there a better way i can declare these? an a regex that would world for every country in the world?
Thanks
You can use character class to reduce the regex e.g.
var ukM = /07[0-9]\d{7,8}$/;
var ireM = /08[35-9]\d{7,8}$/;
...
You can change it on:
var ukM = /(07\d)\d{7,8}$/;
var ireM = /(08[35-79])\d{7,8}$/;
var ireL = (01|2[1-9]|040[24]|04[1-79]|050[45]|05[1-36-9]|06[1-9]|07[14]|09[0-9]\d)\d{7,8}$/;
var usaM = /(713|07[1-9])\d{7,8}$/;
var usaL = /(20[1-9]|2[12]\d|23[1469])\d{7,8}$/;
Related
Instead of "var instance = ..." adding the two values it concatenates them. Can anyone suggest what I need to fix?
I'm trying to add "var startingEmail" value and "var k".
Thank you for your help!
var startingEmail = sheet.getRange("C2").getDisplayValue();
var numEmails = sheet.getRange("E2").getDisplayValue();
var max = numEmails;
for (var k = 0; k<max; ++k){
var threads = GmailApp.getInboxThreads(startingEmail,max)[k]; //get max 50 threads starting at most recent thread
var messages = threads.getMessages()[0];
var sndr;
var rcpnt;
var srAry = [];
var sndr = messages.getFrom().replace(/^.+<([^>]+)>$/, "$1"); //http://stackoverflow.com/questions/26242591/is-there-a-way-to-get-the-specific-email-address-from-a-gmail-message-object-in
var sndrLower = sndr.toLowerCase;
var rcpnt = messages.getTo().replace(/^.+<([^>]+)>$/, "$1");
var rcpntLower = rcpnt.toLowerCase;
var cc = messages.getCc().replace(/^.+<([^>]+)>$/, "$1");
var ccLower = cc.toLowerCase;
//srAry.push(sndr);
//srAry.push(rcpnt);
//srAry.push(cc);
var isIn = joinAddr.search(sndr || rcpnt);
if(isIn == -1){
var instance = k;
I can't see the example in your code but it sounds like you can just wrap Number() around your variable and it will perform the type conversion so the code will perform the math instead of concatenating as strings.
Using JavaScript I want to take a string like this var hashStr = 'modal-123456' and assign the string left of the - to a variable and the string right of the - to another variable.
If the string does not contain a - then ignore it.
How can I best achieve this?
var hashStr = location.hash.replace('#', '');
// hashStr now === 'modal-123456'
var firstHalf = // modal
var secondHalf = // '123456'
You can use split API.
var hashStr = 'modal-123456'
var splitStr = hashStr.split('-');
console.log(splitStr[0])
console.log(splitStr[1])
Just use split.
var hashStr = 'modal-123456';
var [firstHalf, secondHalf] = hashStr.split("-");
console.log("first half:", firstHalf);
console.log("second half:", secondHalf);
Simply
var hashStr = location.hash.replace('#', '');
var firstHalf = hashStr.split("-")[0];
var secondHalf = hashStr.split("-")[1];
or
var hashStr = location.hash.replace('#', '').split("-");
var firstHalf = hashStr[0];
var secondHalf = hashStr[1];
I have data two sets of data as follows:
"One.Two.Three.Four"
"One.Two.Three.1.Four"
The first three parts are fixed and the remaining can extend to as many as possible.
I am trying to build an object where I want to split and combine whatever is present after three into an object.
var split = samplestr.split('.');
var finalarray = [];
if(split.length>4)
{
finalarray[0] = split[0];
finalarray[1] = split[1];
finalarray[2] = split[2];
finalarray[3] = split[3]+"."split[4];
}
I need to generalise this such that even if the string is of the form
"One.Two.Three.1.2.3.Four"
finalarray[3] = 1.2.3.Four;
Any hints on generalising this?
With Array#shift and Array#join.
var split = samplestr.split('.');
var finalarray = [];
if(split.length > 4) {
finalarray[0] = split.shift();
finalarray[1] = split.shift();
finalarray[2] = split.shift();
finalarray[3] = split.join(".");
}
simply replace
finalarray[3] = split[3]+"."split[4];
with
finalarray[3] = split.slice(3).join(".");
Split the string, slice the first part and append the join'ed second part:
console.info=function(x){document.write('<pre>'+JSON.stringify(x,0,3)+'</pre>')}
//--
var str = "One.Two.Three.Four.More.Stuff";
var s = str.split('.');
var result = s.slice(0, 3).concat(s.slice(3).join('.'));
console.info(result);
how can i make this work:
var storedValues = $('<table class="table_groessentabelle_custom"></table>');
// contains excel paste content from Libreoffice
$('textarea[name=excel_data]').bind("paste", function(e){
var pastedData = e.originalEvent.clipboardData.getData('text/html');
storedValues.append(pastedData);
});
//localisation - tables (just a subset)
var de = ["Größe","Höhe","Weite","Damen","Herren","Kinder",];
var fr = ["Pointure","Hauteur","Largeur","Femme","Homme","Enfants"];
var de_storedvalues = JSON.parse(JSON.stringify( storedValues.html() ));
var fr_storedvalues = JSON.parse(JSON.stringify( storedValues.html() ));
for (var i = 0; i < de.length; i++) {
// doesnt work, no fields are translated
fr_storedvalues = fr_storedvalues.replace(/de[i]/gi,fr[i]);
}
it works without the /gi flag but only transates the first entry of a given variable. if there is more than one entry, the rest stays in german.
Thanks in advance,
Michael
var find = de[i];
var regex = new RegExp(find, "g");
fr_storedvalues = fr_storedvalues.replace(regex,fr[i]);
I have a URL : http://localhost:8080/school/teacher/reports/chapter-quiz/student
Getting the last segment, I just need to do this
var lastSegment = location.pathname.split('/').pop();
But how do I grab the one next to the last one ? chapter-quiz
I'd say something like this?
var segments = location.pathname.split('/');
secondLastSegment = segments[segments.length - 2];
Split the segments
var pathArray = window.location.pathname.split( '/' );
Create Variables
var segment_1 = pathArray[1];
var segment_2 = pathArray[2];
var segment_3 = pathArray[3];
var segment_4 = pathArray[4];
Use it
console.log(segment_4) --> chapter-quiz
you can use this
var t = window.location.pathname.split("/")
t.pop();
t.pop();
t.pop();