Re: Using a RegEx as a "variable" WITHIN an array?



This is not my specialist subject at all - so I dont think I can offer you
much help.. The regexp parser in .NET is based on the perl matcher, whihc I
believe the PHP one is also based upon. I think a match on any numeric
combination of 1 or more numerics in this instance would give you your
wildcard.

+\d

or even what you have in ^1.8.9 as a starts with value, which it appears to
be what your doing in PHP.

if you concat this to the banned ip whos range your interested in, and then
add this to your array - you could then do a pattern match on the array
items.

--
Regards

John Timney
ASP.NET MVP
Microsoft Regional Director

"Friday" <friday@xxxxxxxxxxx> wrote in message
news:150520051048128285%friday@xxxxxxxxxxxxxx
> Being an Old L.A.M.P guy, I beg you to please excuse my ignorance of
> dot.net (and all things Windows, for that matter).
>
> As part of an experiment (to learn enough ASP/VB.net to port a series
> of existing PHP scripts of mine to work on IIS), I have created the
> following simple function to compare a Website visitor's IP address
> against a varabe-array. The experiment invovleas a common scenario --
> banning a Website visitor by IP Address:
>
> ##########################
> function BannedIP(sIPAddress As String) As Boolean
>
> Dim selCriteria as String
> selCriteria = sIPAddress
>
> Dim sBanned() As String = {"1.2.3.4","1.5.6.7","1.8.9.10"}
> If Array.IndexOf(sBanned, selCriteria) > -1 Then
> BannedIP = True
> End If
> End Function
> ###########################
>
> The function is called from the top of an ".aspx" page as follows:
> ###########################
> if BannedIP(sIPAddress) then
> Server.Execute("Get-Lost.aspx")
> Response.End
> End If
> ' Otherwsie display the page below
> ###########################
> This works fine.
>
>
> ************************************************
> NOW THEN, to my question....
> ************************************************
>
> Suppose I want to ban everyone from an ENTIRE C-block, e.g.: "1.8.9.*"
> Assuming (as I've found from my reserarch) that VB/ASP/.NET have no
> built-in equivalent to PHP's "preg_match()"...
>
> How do I (using as little code as possible) match the user's IP against
> an array that looks something like:
> ########################
> Dim sBanned() As String = {"1.2.3.4","1.5.6.7","1.8.9.*","1.10.11.12"}
> ########################
>
> (In PHP, using preg_match(), my array-variable would look like this:
> *********
> $Banned = "^1.2.3.4|^1.5.6.7|^1.8.9|^1.10.11.12";
> ereg_replace (" ", "", $ipaddress);
> if(preg_match ("/$Banned/i", "$ipaddress"))
> {
> return true;
> }
> **********)
>
> I was hoping I could simlpy add a wildcard character (of some sort) to
> the C-block entry in the array variable (as in the above example), but
> of course, that would be too simplek.
> :-(
>
> Soooo.... my next thought was, let's create a varaible, based on a
> simple regex, that I can "plug-in" to those C-block entires in my
> array...
> ... something (crudely) like this:
> ###############
> Dim sWC as New Regex = {"([0-9]*)"}
> or...
> Dim sWC As New Regex([0-9]*)
> or...
> Dim sWC() As String = {"Reg_exp.pattern([0-9]*)"}
>
> ... I'm not worried about the actual regex syntax at this point, but I
> think you get the idea.
> ##################
>
> THEN... I simply "add my variable to my variable" in the array (Excuse
> my English, but I'm an American):
> ###################
> Dim sBanned() As String =
> {"1.2.3.4","1.5.6.7","1.8.9..sWC","1.10.11.12"}
> ...
> If Array.IndexOf(sBanned, selCriteria) > -1 Then
> BannedIP = True
> ...
> #####################
> (I KNOW, I KNOW....)
>
> I'm sure my whole idea of using a regex to define a variable within a
> variable within an array variable is pretty(VERY) lame., BUT that's
> why I'm here.
> 8-P
>
> TIA for any Ideas on How to Best Do This,
> :-)
> Friday
>
> --
> #####################################
> "The people cannot be all, & always well informed. The part which is wrong
> will
> be discontented in proportion to the importance of the facts they
> misconceive.
> If they remain quiet under such misconceptions it is a lethargy, the
> forerunner
> of death to the public liberty. What country before ever existed a century
> & a
> half without a rebellion? & what country can preserve it's liberties if
> their
> rulers are not warned from time to time that their people preserve the
> spirit
> of resistance? Let them take arms... The tree of liberty must be refreshed
> from
> time to time with the blood of patriots & tyrants"
> -- Thomas Jefferson
> #####################################


.



Relevant Pages

  • Re: Need help on PHP for MPE/ix
    ... Here is the syntax of the dbupdate intrinsic in PHP: ... assoc array of item values) ... Please let me know if you have any more suggesstions to solve this problem. ... Pavan Kumar Rati wrote: ...
    (comp.sys.hp.mpe)
  • Re: Need help on PHP for MPE/ix
    ... If one item is an array, it must be declared as such in the list ... So, please show us the declaration of the record buffer, and its ... Of Pavan Kumar Rati ... Need help on PHP for MPE/ix ...
    (comp.sys.hp.mpe)
  • Re: attempting to return values from array from w/in a function
    ... What I get is an array w/ only the most recent array entry. ... I am new to PHP & do not have formal scripting ... you end up comparing strings, but the test you mean probably is simply: ... case 1: {codeblock} ...
    (comp.lang.php)
  • Re: Advice about fetching user information
    ... but actually *selecting* them in MySQL ... PHP scripts and use a gaugefunction to time pretty much every ... The same is pretty much true for searching an array in PHP - ... But I wouldn't be searching. ...
    (comp.lang.php)
  • Re: need to send email to 1000 addresses (currently in MS Excel)- whats the best way to do that, cre
    ... > coding each line as an array then looping through the array with mail. ... >> don't post a question that doesn't have anything to remotely do with PHP, ... one huge string) and then it splits that string into an array of arrays. ... CC it, or even better, BCC it so that those being emailed can't ...
    (comp.lang.php)