1

I have url something like this

/test/test123/e/account/data/element?bUnit=17&name=cId&formName=TestForm&value=[self]

I just want to get first querystring and replace value of it so i tried

[\?&]([^=]+)\=([^&]+)

Here is example url https://regex101.com/r/6qCllM/3

But getting all querystrings. I already have tried, just little mistake which want to fix. Don't want multiple lines of function.

How to get only one Query string and replace?

Thanks

Bhumi Shah
  • 9,323
  • 7
  • 63
  • 104
  • Can you explain what exactly you're trying to select and replace? That whole substring is indeed *one* query string – CertainPerformance Oct 05 '18 at 05:37
  • put your inputs and expected out. – The Scientific Method Oct 05 '18 at 05:38
  • 1
    If you only want the first one, then why use `&`? Change `[\?&]` to `[\?]` and it works in your refex101 – freedomn-m Oct 05 '18 at 05:41
  • If you want to find/replace a *specific* parameter (which sounds much more useful than just the first), then : https://stackoverflow.com/questions/5999118/how-can-i-add-or-update-a-query-string-parameter (and many other already answered questions that ask the same thing) – freedomn-m Oct 05 '18 at 05:44

1 Answers1

2

remove the first &, this should work

[\?]([^=]+)\=([^&]+)
The Scientific Method
  • 2,374
  • 2
  • 14
  • 25