2

Hello friends i want to make a function that remove specific group of words from input link before doing search :

i got this coding :

jquery :

<script type="text/javascript">
        function GetIdinfo() {
            var q = document.getElementById("graph").value;
            window.open("http://graph.facebook.com/" + q,"", "width=500px, height=300px");
        }
    </script>


HTML :

<form action="index.php" method="get">
<input id="graph" type="text" name="q" size="20" placeholder="Guru.of.Fun or 100XXXX"/></td>
<input type="button" name="graph" value="Get Facebook Data" class="submit" onclick="GetIdinfo()" />

and now i want to get some help to remove https://graph.facebook.com/ and only read text after back slash / for example :

100008622 from full link https://www.facebook.com/100008622
  • if any user enter in search text area..

3 Answers 3

2

You can use regex

var regex = /\d+/g;
var string = "https://www.facebook.com/100008622";//window.location.href you can use directly this;
var matches = string.match(regex);  
alert(matches);

Jsfiddle

Sign up to request clarification or add additional context in comments.

1 Comment

Further more @Somnath i'm learner so would you please refer me any site with tutorials, where i can learn new row in table by clicking new and then save add text in row thanks a bunch!
1

You can use .split().pop():

var url = document.getElementById("graph").value;
var value = url.split('/').pop();

Here the .split() makes an array out of the url and .pop() returns the last value in the array.


You can see the test here.

var url = 'https://www.facebook.com/100008622';
var value = url.split('/').pop();
alert(value)

2 Comments

i would like to repeat that what i'm asking for : if user type full address in search box then coding pick text after **https://www.facebook.com/**
Further more @Jai i'm learner so would you please refer me any site with tutorials, where i can learn new row in table by clicking new and then save add text in row thanks a bunch!
0

You should use Regex replace function

var str = "https://www.facebook.com/100008622";
str.replace(/https:\/\/www.facebook.com\//i, ""); 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.