Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 293023
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T06:14:01+00:00 2026-05-12T06:14:01+00:00

I’m matching urls, so I can connect requests to controllers/views, and there are multiple

  • 0

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.

Examples:

  • /admin/something #match
  • /admin/something/new #match
  • /admin/something/new/id #fail
  • /admin/something/edit #fail
  • /admin/something/edit/id #match

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.

The regex I’ve been using so far:

^/admin/something(?:/(?P<action>new|edit(?:/(?P<id>\d{1,5}))))?$

A whitespace-exploded version:

^/admin/something(?:/
    (?P<action>
        new|        # create a new something
        edit(?:/    # edit an old something
                (?P<id>\d{1,5})    # id to edit
            )
        )
    )?    # actions on something are optional
$

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.

The lookahead regex I’ve been working at: (will match ‘new’, but not ‘edit’ [with or without an id])

^/admin/something(?:/(?P<action>new|edit(?=(?:/(?P<id>\d{1,5})))))?$

Any tips/suggestions would be much appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T06:14:01+00:00Added an answer on May 12, 2026 at 6:14 am

    Your problem lies with the $ at the end. This is a zero-width assertion that the regex matches to the end of the line. However, your lookahead is also a zero-width assertion (that id follows edit). The reason it’s called a lookahead is because it matches within the lookahead, and then skips back to the beginning of that match. So it’s failing on …edit/id because it’s trying to assert both that /id follows edit and /edit is the end of the line. It fails on …edit alone because it’s trying to assert that /id follows edit.

    There are two potential solutions. The first is to simply take out the $. This may not be desirable because then it could match …/edit/id/gobbledygook. The second solution is to use your regex language’s method of reusing captured groups. I can’t help you there because I don’t know what regex you’re using. I don’t recognize the P<name> syntax for named capturing. You would put whatever you need for that after the <action> group.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
Does anyone know how can I replace this 2 symbol below from the string

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.