1

I'll read more about RegEx in near future, but for now i can't get RegEx for the following:

?filter=aBcD07_1-&developer=true

Need to get only aBcD07_1-, without other. Can you please help and provide me a RegEx for javascript

Thanks!

  • possible duplicate of [Get query string values in JavaScript](http://stackoverflow.com/questions/901115/get-query-string-values-in-javascript) – Álvaro González Apr 17 '12 at 07:26

2 Answers2

1

Try with this one:

var rx = /[?&]filter=([a-zA-Z0-9_-]+).*/g;

var result = rx.exec(yourGetStr);

if (result && result.length == 2) {
    alert (result[1]);
}

This regular expression will work even when filter is not the first query parameter.

Robert Koritnik
  • 103,639
  • 52
  • 277
  • 404
1

A simple substring and indexOf should do the trick.

var startIndex = str.indexOf('filter=') + 7;
str.substring(startIndex, str.indexOf('&', startIndex)); // returns "aBcD07_1"
Kemal Fadillah
  • 9,760
  • 3
  • 45
  • 63