javascript 在 . (点)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4089411/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
javascript grab part of a string after a . (dot)
提问by MEM
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;
假设我们有这个字符串:“mydomain.bu.pu”,我想获取其中的“.bu.pu”部分;
I'm thinking about using something like:
我正在考虑使用类似的东西:
indexOf and later substr ... But I confess I'm kind of lost...
indexOf 和后来的 substr ......但我承认我有点迷茫......
Any help please? :D
请问有什么帮助吗?:D
Thanks in advance, MEM
提前致谢,MEM
回答by kijin
var afterDot = str.substr(str.indexOf('.'));
回答by Onite
s = s.substring(s.indexOf("."));
That should do the trick.
这应该够了吧。
回答by Ryan
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 );
回答by S. Domeng
maybe this is too late to consider, but this codes works fine for me using jquery
也许现在考虑为时已晚,但这些代码对我使用 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
- lkjasdf_alksjd_ksdf.jpg = ksdf.jpg
- aaa_bbb_ccc.jpg = ccc.jpg
- testing_image.jpg = image.jpg
You could just replate '_' to '.'
你可以把'_'重新改成'.'
回答by vijith
sixCommaTwoValidation method for numeric 6,2 validation and restiction.
SixCommaTwoValidation 方法用于数字 6,2 验证和限制。
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;

