0

I have string like this: http://someurl.com?someparameter=dhws6sd6cvg and i would like to mach part from first letter to '=' with javascript regex. Is it possible?

Fraser
  • 15,275
  • 8
  • 53
  • 104
user1222312
  • 63
  • 1
  • 1
  • 6

4 Answers4

2

The use of .* will cause the regex to back track and use of () will create a backreference. So we can use this to capture the given string ^[^=]+=

Devin Burke
  • 13,642
  • 12
  • 55
  • 82
2

You can create a group which will match all the words starting from the beginning till the =. You can then access the regex group as shown here.

Something like: ^(.*?)= Should yield the following group value: http://someurl.com?someparameter. If you would like to include the =, then, just do as follows: ^(.*?=)

Community
  • 1
  • 1
npinti
  • 51,780
  • 5
  • 72
  • 96
2

Up front: If you're parsing URLs, you might want to use one of the existing URL parsers or URI.js.

The beginning of a string is denoted by ^ so your RegEx could look like ^([^=]+). This matches everything but = from the beginning of the string. If you only want the part after the ?, try \?([^=]+). Note that you'll only get the very first parameter this way.

Have a look at MDN explaining RegExp.

rodneyrehm
  • 13,442
  • 1
  • 40
  • 56
1

This pattern should match until =:

.+?=
Sufian Latif
  • 13,086
  • 3
  • 33
  • 70