Regular Expression to match ranges of numbers except some certain ranges of numbers and some particular numbers

I am creating a user security policy for each user. Each user security policy will have a regular expression statement in it.

Each webpage has its own unique ID in numeric format ranging from 0 to 100000. When a user accesses a webpage, the system will check the webpage's ID against the user's security policy expressing in regular expression.

For instance, a user has the access to all webpages (ID ranging from 1 - 100000) except webpages with ID number 2, 54, 109 to 2001 and 10521. How can I write an efficient regular expression to tackle this requirement?

Answers


You will find this will be both a programmatic nightmare to maintain and a significant performance overhead to accomplish the task. You would likely find it much more effective (and less cumbersome) to work with lists instead. You could store these lists in a database, or even using a cloud service provider that communicates with a RESTful api and json.

An example, written in php (mostly pseudo code), assuming the permissions have already been retrieved from the data storage:

//user1 is logged in and has access to the following array of allowed pages:
$loggedInUserPerms = array(1,6,99,821,983255);
if (in_array($pageID, $loggedInUserPerms))
{
    //the logged in user has access to this page
}
else
{
    //the logged in user doesn't, display access denied error
}

You could even expand this principle and use multidimensional arrays:

$loggedInUserPerms = array(
    1=>array("read"),
    6=>array("read","write"),
    9=>array("read","write"),
    821=>array("read","write","delete"),
    983255=>array("read")
);
if (in_array($pageID, $loggedInUserPerms))
{
    //the logged in user has access to this page

    //you can now handle the sub arrays as well 
    //to determine what level of access the user has.
}
else
{
    //the logged in user doesn't, display access denied error
}

Need Your Help

How to convert an IEnumerable<IEnumerable<T>> to a IEnumerable<T>

c# collections extension-methods

I have an IEnumerable&lt;IEnumerable&lt;T&gt;&gt; collection that I want to convert to a single dimension collection. Is it possible to achieve this with a generic extension method? Right now I'm d...

How to set capacity for Java DelayQueue

java multithreading concurrency queue java.util.concurrent

I was using LinkedBlockingQueue queue to implement producer-consumer pattern for TCP/IP events transfer, I was using boolean offer(e) which means once the queue is reach its capacity, the new incom...