Using Extract REGEX to leave only the Booking Reference from a URL String

32 Views Asked by At

I am attempting to extract data from the following string leaving me with only the booking reference, I have successfully done this with the Recipient ID reference but not the Booking reference.

URL /information/feedback?RECIPIENT_ID=fb8eab5f4738ad75e5093ee0f57ce1eb,fb8eab5f4738ad75e5093ee0f57ce1eb&BkRef=20927158&pid=email&sid=nfprog.

I have used the following to extract the Recipient ID which works REGEXP_EXTRACT(Page,'.RECIPIENT_ID=(.*),.*') but not having any luck with the booking reference.

The BkRef will always be the same length i.e. 8 numerical characters BkRef=20927158

1

There are 1 best solutions below

1
Wiktor Stribiżew On

You can use

[?&]BkRef=([^&]*)

See the regex demo.

Details:

  • [?&] - either ? or &
  • BkRef= - the name of the attribute
  • ([^&]*) - Capturing group 1: zero or more chars other than &.

If there can be name references after the param, you can replace ([^&]*) with ([^&#]*).