I am writing an HTTP request tutorial for beginners. I have code that looks like:
import requests
r = requests.get('http://xxx.com/yy/zzz?a=1&b=2', auth=('1234', '5678'))
r.text
I would like to use jQuery to dynamically select the `?a=1&b=2~ snippet of code and highlight it (because those values are dynamic and depend on what the user types in).
Is there a way to do a jQuery select that matches a regex?
Unfortunately I can not wrap that area in a special span to select it that way.
Thanks!
You could achieve this by using the element that contains the code sample, which I assume you’ve put in a
<pre>or<code>block. Then you can just grab all of the html contents of it, and use a regular string replace to add in any additional HTML elements you might need.Here is jsFiddle Example which has the code you provided in a
<pre>tag and adds a span around the query string.