I'm unable to read regex.开发者_运维百科
Let's say we have this string: "mydomain.bu.pu" and I want to grab the ".bu.pu" part of it;
I'm thinking about using something like:
indexOf and later substr ... But I confess I'm kind of lost...
Any help please? :D
Thanks in advance, MEM
var afterDot = str.substr(str.indexOf('.'));
The above answers include the dot in the string. If you only want what's after the dot:
var afterDot = str.substr( str.indexOf('.') + 1 );
s = s.substring(s.indexOf("."));
That should do the trick.
Here is the three simple way I know.
const text = "Allah is great. Allah is only one"
const methodOne = text.split('.');
console.log(methodOne[0]); // BEFORE DOT
console.log(methodOne[1]);
const methodTwo = text.slice(text.indexOf('.')+1);
console.log(methodTwo);
const methodThree = text.substring(text.indexOf(".")+1);
console.log(methodThree)
sixCommaTwoValidation method for numeric 6,2 validation and restiction.
var afterDot = '';
var beforeDots = inputValue.split('.');
var beforeDot = beforeDots[0];
if(beforeDots[1]){
var afterDot = beforeDots[1];
if(afterDot.length > 3 ){
afterDot = afterDot.slice(0, 2);
}
afterDot = '.'+ afterDot;
}
if(beforeDot){
if(beforeDot.length > 6 ){
beforeDot = beforeDot.slice(0, 6);
}
if(beforeDots[1] == ''){
beforeDot = beforeDot + '.';
}
}
inputValue = beforeDot + afterDot;
return inputValue;
maybe this is too late to consider, but this codes works fine for me using jquery
var afterDot = value.substr(value.lastIndexOf('_') + 1);
- lkjasdf_alksjd_ksdf.jpg = ksdf.jpg
- aaa_bbb_ccc.jpg = ccc.jpg
- testing_image.jpg = image.jpg
You could just replate '_' to '.'
精彩评论