0

I have a JavaScript block from where I need to extract a value. it look something like this:

<script type="text/javascript">
//<![CDATA[
window.gon={};gon.session_id="1a2b3c4d5e";gon.user={"id":"5a4b3c2d1e"}
//]]>
</script>

I need to get value for id. I tried with multiple options but doesn't seems to be working. E.g. script type="text/javascript" gon.user.id="(.+?)"

PS: gon is gem used to pass dynamic variables in Javascript block.

Erkan Demirel
  • 4,302
  • 1
  • 25
  • 43
  • This might sound like a stupid question but why can't you use `gon.session_id` directly? Are you not using the ID in the JS code directly? – Risadinha Mar 24 '16 at 10:00

1 Answers1

0

The regex will be

/"id":"(\d*\w*)"/i

The above pattern will search for the value in "id":"5a4b3c2d1e" pattern and will return 5a4b3c2d1e.

https://regex101.com/ is an awesome site to play around with Regex.