1

I have a string and I need to match a pattern and discard the rest of the string after the first occurrence of a delimiter after the patter matched

sample string :

_fw_xx_app_id=xxxxx&adobe_id=59742375247590810332565440942222920249&krux_user=yyyyyyy&User_Agent=zzzzzz&_fw_did_idfa=aaaaaaa&_fw_dpr=2.00&_fw_ae=nonauthenticated&_fwu%3A386123%3Atqxqle5of=1&_fwu%3A386123%3Atshc3wdb8=1

I want to extract only the value that is after key '_fw_ae=' until the first occurrence of &

I tried this

regexp_substr(all_request_kv,'_fw_ae=(.+?)&|$',1,1,'e')

but this is bringing everything after the _fw_ae= like below

_fw_ae=nonauthenticated&_fwu%3A386123%3Atqxqle5of=1&_fwu%3A386123%3Atshc3wdb8=1 where as i only want nonauthenticated in this example

Emma
  • 27,428
  • 11
  • 44
  • 69
pavan kumar
  • 75
  • 1
  • 7

1 Answers1

2

Instead of a non greedy quantifier, you could use a negated character class [^&] matching not an & inside a capturing group:

_fw_ae=([^&]+)

Regex demo

The fourth bird
  • 154,723
  • 16
  • 55
  • 70
  • 1
    worked like a charm, thank you! I'm doing it on Snowflake – pavan kumar May 08 '19 at 15:46
  • You are welcome. I think this is the [documentation](https://docs.snowflake.net/manuals/sql-reference/functions-regexp.html#general-usage-notes) which you can use as a reference to check what is supported. I see that it uses POSIX ERE and as far as I know that does not support non greedy quantifiers like `.+?` – The fourth bird May 08 '19 at 16:04