← Lesson
Regular Expressions
Joeven
Run
Reset
Python loads on first run
import json import re messy = 'Sure. Here is the data: {"city": "Paris", "ok": true} thanks' blob = re.search("[{].*[}]", messy) if blob: data = json.loads(blob.group()) print("city", data["city"]) print("ok", data["ok"]) text = "see https://example.com/a and https://example.com/b please" print("urls", re.findall("https://[^ ]+", text)) step_line = "error at step 9 of 20" m = re.search("step ([0-9]+)", step_line) if m: print("whole", m.group(0)) print("group1", m.group(1)) no_link = re.search("https://[^ ]+", "no link here") if no_link: print(no_link.group()) else: print("no url") clean = '{"n": 3}' print("json.loads", json.loads(clean))
Run to execute this in your browser. Nothing is sent to a server.