Note that there are some explanatory texts on larger screens.

plurals
  1. POGetting some elements in a string using a regex
    primarykey
    data
    text
    <h2>Context</h2> <hr> <p>Using Ruby I am parsing strings looking like this:</p> <p>A type with an ID...</p> <pre><code>[Image=4b5da003ee133e8368000002] [Video=679hfpam9v56dh800khfdd32] </code></pre> <p>...with between 0 and n additional options separated with @...</p> <pre><code>[Image=4b5da003ee133e8368000002@size:small] [Image=4b5da003ee133e8368000002@size:small@media:true] </code></pre> <p>In this example:</p> <pre><code>[Image=4b5da003ee133e8368000002@size:small@media:true] </code></pre> <p>I want to retrieve:</p> <ol> <li>[Image=4b5da003ee133e8368000002@size:small@media:true]</li> <li>Image</li> <li>4b5da003ee133e8368000002</li> <li>size:small</li> <li>media:true</li> </ol> <h2>Problem</h2> <hr> <p>Right now using this regex:</p> <pre><code>(\[([a-zA-Z]+)=([a-zA-Z0-9]+)(@[a-zA-Z]+:[a-zA-Z]+)*\]) </code></pre> <p>I get...</p> <ol> <li>[Image=4b5da003ee133e8368000002@size:small@media:true]</li> <li>Image</li> <li>4b5da003ee133e8368000002</li> <li>@media:true</li> </ol> <p>What am I doing wrong? How can I get what I want? </p> <p><em>PS: All the results are copied from <a href="http://rubular.com/" rel="nofollow noreferrer">http://rubular.com/</a> which is nice to debug regex. Please use it if it can help you help me :)</em></p> <hr> <p>Edit : if it's impossible to get all options separated, how could I get this:</p> <ol> <li>[Image=4b5da003ee133e8368000002@size:small@media:true]</li> <li>Image</li> <li>4b5da003ee133e8368000002</li> <li>@size:small@media:true</li> </ol>
    singulars
    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.
 

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