Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

javascript grab part of a string after a . (dot)

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

like image 338
MEM Avatar asked Nov 03 '10 16:11

MEM


3 Answers

var afterDot = str.substr(str.indexOf('.'));
like image 158
kijin Avatar answered Nov 03 '22 02:11

kijin


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 );
like image 30
Ryan Avatar answered Nov 03 '22 00:11

Ryan


s = s.substring(s.indexOf("."));

That should do the trick.

like image 8
Onite Avatar answered Nov 03 '22 01:11

Onite