Note that there are some explanatory texts on larger screens.

plurals
  1. PORegex lookahead within option group
    primarykey
    data
    text
    <p>I'm matching urls, so I can connect requests to controllers/views, and there are multiple options for a few of the urls, only one of which can have anything following it in the url, but I also need to have what comes after available as a named group.</p> <p>Examples:</p> <ul> <li>/admin/something #match</li> <li>/admin/something/new #match</li> <li>/admin/something/new/id #<strong>fail</strong></li> <li>/admin/something/edit #<strong>fail</strong></li> <li>/admin/something/edit/id #match</li> </ul> <p>There are many other possibilities, but thats good enough for an example. Basically, if the url ends in 'new', nothing can follow, while if it ends in 'edit' it also must have an id to edit.</p> <p>The regex I've been using so far:</p> <pre><code>^/admin/something(?:/(?P&lt;action&gt;new|edit(?:/(?P&lt;id&gt;\d{1,5}))))?$ </code></pre> <p>A whitespace-exploded version:</p> <pre><code>^/admin/something(?:/ (?P&lt;action&gt; new| # create a new something edit(?:/ # edit an old something (?P&lt;id&gt;\d{1,5}) # id to edit ) ) )? # actions on something are optional $ </code></pre> <p>But then if the url is '/admin/something/edit/id' the 'action' group is 'edit/id'. I've been using a little bit of string manip within the controller to cut down the action to just... the action, but I feel like a positive lookahead would be much cleaner. I just haven't been able to get that to work.</p> <p>The lookahead regex I've been working at: (will match 'new', but not 'edit' [with or without an id])</p> <pre><code>^/admin/something(?:/(?P&lt;action&gt;new|edit(?=(?:/(?P&lt;id&gt;\d{1,5})))))?$ </code></pre> <p>Any tips/suggestions would be much appreciated.</p>
    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.
    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