The simplified code:
SELECT 'ok' WHERE '/articles/new/' ~ '^/articles/(?!new)([\w-]+)/$';
Examples, what I want:
'/articles/new/' => ''
'/articles/new-york/' => 'ok'
'/articles/other-string/' => 'ok'
And, what's wrong:
'/articles/new/' => ''
'/articles/new-york/' => '' /* Wrong */
'/articles/other-string/' => 'ok'
So, how can I block ONLY the word?
Optimization
In PostgreSQL database, I have a table (page
), and it has got columns path, title, file, regex_path etc.
The values in column path
look like this:
/
/articles/
/articles/:category-code/
/articles/:category-code/:article-code/
/articles/:category-code/:article-code/edit/
/articles/new/
/members/
/members/:username/
:
means it's a parameter (PHP gets the name and content based on regex_path – the first version)
From outside (PHP) the database gets a value (URL). Examples:
/ /* Main page */
/articles/ /* List all article */
/articles/it/ /* List articles in IT category */
/articles/it/ipad-mini-2/ /* Article */
/articles/it/ipad-mini-2/edit/ /* Edit article */
/articles/new/ /* New article */
/members/ /* Member list */
/members/someone/ /* Member datasheet */
How can I select the right row, where the value (URL) matches with the path (the fastest way, without regex)?
Example
In: /articles/it/ipad-mini-2/
Out: the row, where path
is: /articles/:category-code/:article-code/