I'm using Javascript to grab a variable passed through the URL:
function get_url_parameter( param ){
param = param.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
var r1 = "[\\?&]"+param+"=([^&#]*)";
var r2 = new RegExp( r1 );
var r3 = r2.exec( window.location.href );
if( r3 == null )
return "";
else
return r3[1];
}
Once I have the parameter required
var highlightsearch = get_url_parameter('search');
I want to be able to delete all of the string after the ">".
e.g
The result currently looks like this:
highlightsearch = "Approved%20XXXXX%20XXXXX>YYYY%20YYYYYYY%20YYYY%20-%20YYYY%20YYYY";
After my string manipulation I want it to hopefully look like
highlightsearch = "Approved%20XXXXX%20XXXXX";
Any help would be great.
Yi Jiang
50.2k16 gold badges139 silver badges137 bronze badges
-
1Shameless plug, but your URL param function isn't very efficient, it doesn't work with encoded params or decode the result. See stackoverflow.com/questions/901115/… for a more robust solution.Andy E– Andy E2010年11月10日 10:01:13 +00:00Commented Nov 10, 2010 at 10:01
-
Thanks Andy, learning a lot this evening!darrenhamilton– darrenhamilton2010年11月10日 10:18:21 +00:00Commented Nov 10, 2010 at 10:18
2 Answers 2
The following will get you everything before the ">":
var highlightsearch = get_url_parameter('search');
// highlightsearch = "1234>asdf"
highlightsearch = highlightsearch.slice(0, highlightsearch.indexOf(">"));
// highlightsearch = "1234"
answered Nov 10, 2010 at 9:58
stpe
3,6283 gold badges35 silver badges39 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
Regular expression to match ">" and everything after it: >.*
highlightsearch = highlightsearch.replace(/>.*/, '')
1 Comment
darrenhamilton
Thanks folks. Working on it now.
lang-js