Note that there are some explanatory texts on larger screens.

plurals
  1. PORegEx for 15 character alpha-numeric character within JSON
    primarykey
    data
    text
    <p>I am using RegEx to assert the response of an API call, but it's currently a little too 'greedy' and ends up matching all kinds of responses. The RegEx bits are needed since the actual IDs in the response will be different each time.</p> <p>The RegEx assertion is this:</p> <pre><code>{data:\[{"name":"Mat","~id":"(.*)"},{"name":"Laurie","~id":"(.*)"}\]},"something":true} </code></pre> <p>Which matches this correct response:</p> <pre><code>{data:[{"name":"Mat","~id":"4fd5ec146fc2ee0fff234234"},{"name":"Laurie","~id":"4fd5ec146fc2ee0fff234227"}]},"something":true} </code></pre> <p>as well as this incorrect response:</p> <pre><code>{data:[{"name":"Mat","~id":"4fd5ec146fc2ee0fff234234"},{"name":"Laurie","~id":"4fd5ec146fc2ee0fff234227"},{"name":"John","~id":"4fd5ec146fc2ee0fff234237"},{"name":"Paul","~id":"4fd5ec146fc2ee0fff234238"},{"name":"George","~id":"4fd5ec146fc2ee0fff234239"}]},"something":true} </code></pre> <p>The second <code>(.*)</code> is not just matching the ID of the second item, but it's matching the ID <em>and</em> all the other <em>unwanted</em> objects.</p> <p>So I guess I need to make my RegEx be a little more strict when it comes to the <code>~id</code> fields. Since the IDs will always be 24 hex characters, I'd like to replace the <code>(.*)</code> with something more appropriate.</p> <ul> <li>I am writing this in <a href="http://www.golang.org/" rel="nofollow">Go</a>, and therefore using Go's <a href="http://golang.org/pkg/regexp/" rel="nofollow">RegExp</a> package.</li> <li>And am using <a href="http://regexpal.com/" rel="nofollow">http://regexpal.com/</a> to test the RegEx</li> </ul>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload