0

I've got a recursive url which can have an infinite amount of ids after the first /pages bit:

/pages/987d6fg8976df898dsa/92834799437324834/923897439874202307/.....

And so on and so on..

As well as have /new or /edit at the end like:

/pages/987d6fg8976df898dsa/92834799437324834/923897439874202307/new
/pages/987d6fg8976df898dsa/92834799437324834/923897439874202307/edit

I need to match these recursive urls, so I came up with these regexp's:

/new:

^\/pages\/[a-zA-Z0-9-]{0,}/new$

/edit:

^\/pages\/[a-zA-Z0-9-]{0,}/edit$

The problem here is that it only matches strings that have one id string, so /pages/93848347s7a87sa9ds7d works but /pages/20839283792839289d/023898473947384349 fails.

I've tried looking for a regexp which solves this but I haven't come across any which suits my needs.

Any idea how I can solve this?

2
  • Split by / and remove empty elements and pages, new & edit from the resulting array. Commented Dec 15, 2017 at 8:35
  • ^/pages/[a-zA-Z0-9/-]*/new$? Commented Dec 15, 2017 at 8:38

2 Answers 2

1

Could you try this

^\/pages\/[a-zA-Z0-9-\/]{0,}\/new$
Sign up to request clarification or add additional context in comments.

Comments

1

I'd use:

/^\/pages\/(?:[a-zA-Z0-9]*\/)*(new|edit)$/

var test = [
    '/pages/987d6fg8976df898dsa/92834799437324834/923897439874202307/new',
    '/pages/987d6fg8976df898dsa/92834799437324834/923897439874202307/edit'
];
console.log(test.map(function (a) {
  return a+' :'+/^\/pages\/(?:[a-zA-Z0-9]*\/)*(new|edit)$/.test(a);
}));

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.