1

I have an environment variable called FIRST and containing a JSON :

{ "claim1": "val1", "claim2": "val2" }

I would like to set a new environment variable which should contain only val1.

I tried to set this new variable (SECOND) using SetEnvIf but unfortunately this doesn't work:

SetEnvIf FIRST (\"claim1\":)(.*?)\"(.*?)\" SECOND=$3

The regex is correct, you can check it here : demo

The FIRST variable is not a request attribute even if it seems to be required according to the Apache Module mod_setenvif documentation..

Any idea how I could achieve this ?

Thanks !

MaryC
  • 11
  • 2
  • try changing to `SECOND=$1` – Matt.G Mar 26 '19 at 16:08
  • I tried this but it's still not working for me. The SECOND variable is empty. – MaryC Mar 26 '19 at 16:39
  • regex is missing a space after the `:`. try `(?:"claim1": ")(.*?)(?:")` .[Demo](https://regex101.com/r/Wa7PJP/1) – Matt.G Mar 26 '19 at 16:43
  • A better regex would be `(?:"claim1" *: *")([^"]+)` [Demo](https://regex101.com/r/Wa7PJP/2) . This should handle spaces. – Matt.G Mar 26 '19 at 16:48
  • Apache seems to refuse the Regex (even if it is correct according to the link below). I have the following error message '"SetEnvIf Regex could not be compiled" – MaryC Mar 26 '19 at 17:23
  • try escaping the double quotes: `(?:\"claim1\" *: *\")([^\"]+)` .[Demo](https://regex101.com/r/Wa7PJP/6) – Matt.G Mar 26 '19 at 17:34
  • I still get the error message. With the following syntax: `SetEnvIf FIRST (\"claim1\":)(.*?)\"(.*?)\" SECOND=$3` I don't get the error message below but the SECOND variable is empty. Any idea ? – MaryC Mar 27 '19 at 08:47
  • Have you tried `(?:"claim1": ")(.*?)(?:")` with `SECOND=$1`? – Matt.G Mar 27 '19 at 13:03
  • Yes I tried this but I get the error message below. – MaryC Mar 27 '19 at 13:07

0 Answers0