regex - Match all characters in group except for first and last occurrence -


I say

  parent / child / child / page-name  

In my browser I want to remove the name of the parent, children as well as the page. Here are the regular expressions that I am currently using. There should be no limit for how many children are in the URL request. For the time, the name of the page will always be in the end and will never leave.

  ^ ([\ w -] {1,}) {1} - & gt; Match Parent (Return 'Parents') (/ (? :(?! /). * * [A-z]) {1,} / - & gt; Join Children (Return / Children / Children) [\ w -] {1,} (?!. * [\ W -] {1,}) - & gt; Match page name (return 'PageName')  

The more I play with this, the more I think, how big is this solution. This is for a small CMS which I am developing in ASP Classic (-). This MVC is like the routing path. But instead of calling the controllers and functions on the basis of URL request, I travel below the hierarchy I am using the appropriate page in the database. The database is using the Nested Set model and linked to a unique page name for each child.

I By experimenting with / delimiter, I found that with all the split statements, it was made very unreadable.

Everyone said, I used to be from parents, kids and strings An effective method is required to parse the page name. Can someone please provide an alternative solution?

To be honest, I'm not sure that regular expression is my problem. Good solution.

Thanks.

>

You can try to use Are:

  ^ ([\ w]] + / (/.*/) ([\ W -] +) $  

and after Reach three Match Group C. Re-done using the Matching SubMatches . See for more information.

Edit

Actually, assuming that you know that [\ w -] is all that parts You can use ^ ([\ w -] +) (. *) ([\ W -] +) $ instead, and it is non-child The case is fine.


Comments