0

I have the following string :

var url = "po1.btr.en.mycompany.com";

I would like to extract the following subdomain ".btr.en.mycompany.com".

How can i do this ?

3
  • You could split on the dot character, then take everything but the first and concatenate them back together with a dot. Commented May 21, 2015 at 14:38
  • What is the pattern of the given url?Is there any? Commented May 21, 2015 at 14:39
  • 2
    There are a bazillion ways to do that. What exactly are the criteria of what should be removed? Commented May 21, 2015 at 14:41

2 Answers 2

0

You can find the match using regex:

<script type="text/javascript">
    var link = "po1.btr.en.mycompany.com";
    var reg = /btr.*\.com/;
    window.alert(reg.exec(link));
</script>
Sign up to request clarification or add additional context in comments.

Comments

0

This should do what you need :)

var url = "po1.btr.en.mycompany.com";
var clean = url.substr(url.indexOf('.') + 1);
alert(clean);

2 Comments

var clean = url.substr(url.indexOf('.') + 1);. You don't need a replace.
Also: alert(clean)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.