0

Trying to remove parts of a URL via RegEx.

I'm getting my content via an AJAX requst thus I cannot use

$(location).attr('search').split("&")[2]

My RegEx (Regex101)

Any direct answer will be greatly appreciated as I cannot comprehend RegEx, other better or more efficient suggestions will also be greatly valued.

  • for most good browsers you may want to look at the [URL object](https://developer.mozilla.org/en/docs/Web/API/URL) – Jaromanda X Jul 30 '16 at 00:13
  • What exactly are you trying to remove from the URL? – Rob M. Jul 30 '16 at 00:14
  • you don't need to specifically use the `location` object, just use `.split()` on whatever url or string is being returned. `\?.+$` will return all of the variables in a url however – Polyov Jul 30 '16 at 00:14
  • @Jaromanda X, Like I said, I'm getting my data via an AJAX query, thus there is no URL to take data from. –  Jul 30 '16 at 00:14
  • Your question states that you are trying to remove parts of a URL ... now you say there is no URL ... you can't have both – Jaromanda X Jul 30 '16 at 00:15
  • 'I'm getting my content via an AJAX requst thus I cannot use $(location).attr('search').split("&")[2]' I have the URL, but not in the fashion of im at the location, its just a string –  Jul 30 '16 at 11:37

2 Answers2

0

Straightforward approach: this question already has helpful answers on how to parse a URL with and without a RegEx. Try one of those methods, then keep the parts you want and discard the ones you don't.

Community
  • 1
  • 1
wirefox
  • 444
  • 12
  • 15
0

Not sure if I got your question fully. For the example you have, this is the regexp I have for your matching. May not be the elegant ones, but it should work for your example.

http[s]*://opskins.com/?loc=shop_search&app=730_2

http[s]://[a-z]+.com/\?[a-z]+=[a-z_]+&[a-z]+=[0-9_]+

Napo
  • 11
  • 3