admitme_sam admitme_sam - 4 months ago 8
Ruby Question

How to write a regex for web scraping

I have this text on a website I want to scrape:

event: new SEvent({"event_id":"Id","date":"Sat 27 Aug 2016"})


I want to pass this from my controller to my JavaScript file, which is already set up.

I'm having issues parsing the information so that only this is returned:

SEvent({"event_id":"Id","date":"Sat 27 Aug 2016"})


Here's what I tried to no avail:

info = text.to_s.scan(/\"(event)/).uniq

hsz hsz
Answer

You can try with following regex:

/event: new (\w+\([^)]+\))/