0

I have a URL that is very similar to:

url/Search/SearchResult?SearchText=FirstName%20Lastname

Using JQ, how can I parse Everything after the "SearchText=" , while replacing %20 with a space.

I'm looking to return a string in the following format:

"FirstName LastName"

I figure this can be done easily with RegEx, but I struggle working with it, so examples would be very helpful.

Thanks

Roko C. Buljan
  • 196,159
  • 39
  • 305
  • 313
Mark
  • 4,773
  • 8
  • 53
  • 91

3 Answers3

1

You can do this

var value = decodeURIComponent(url.split('?')[1].split('=')[1]);
Amit Joki
  • 58,320
  • 7
  • 77
  • 95
0
.*=|%20

Try this.Replace by .See demo.

http://regex101.com/r/hQ1rP0/84

vks
  • 67,027
  • 10
  • 91
  • 124
0

Try this :

var searchText = document.URL.split("SearchText=")[1].split("%20");
var name = searchText[0] + " " + searchText[1];
skirato
  • 763
  • 6
  • 26
  • That's only work if the SearchText was definitely the last parameter, and if there were no escaped characters in the string: you'd need to `uriDecodeComponent` the strings afterwards. But there are more complete solutions on a few other questions here. – Rup Oct 08 '14 at 16:31
  • Can you expand your answer to include an explanation of your code? It helps the reader more than you might think. – gunr2171 Oct 08 '14 at 17:02