Javascript Split URL
arrays, javascript, split
Solution
Split returns an array, use it as an array!
var parts = window.location.pathname.split( '/' );
var query = parts[parts.length-1].split( '.html' );
query[0]= query[0].replace(/-/g," ");
var redirectpath = "http://www.mydomain.com/search/?q="
window.location.href = redirectpath + query[0];
This assuming you always want the part of the url after the last `/`
Problem
I want to SPLIT some specific parts of the URL, here is what i have so far. ``` <script type='text/javascript'> var query = window.location.pathname.split( '/' ); query = window.location.pathname.split( '.html' ); var redirectpath = "http://www.mydomain.com/search/?q=" window.location.href = redirectpath + query; </script> ``` The URL structure will be like this: ``` http://www.mydomain.com/page/2013/05/some-page-title.html ``` The variable `query` outputs like this; `page,2013,05,some-page-title` i only want the `some-page-title` part and also remove the hyphens. so the final output would be `http://www.mydomain.com/search/?q=some page title` how is that possible? Please help!! Thanks