This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

String matching (using string match)

Old posts that have not been replied to for several years.
Locked
User avatar
awyeah
Revered One
Posts: 1580
Joined: Mon Apr 26, 2004 2:37 am
Location: Switzerland
Contact:

String matching (using string match)

Post by awyeah »

Hi,

[#1] I have a channel where I want to match bans containing totally ?????? with the !, @ and wildcards (*).

Bans for example like:

*!*????????*@*
???????*!*@*
*!*@*???????*

If I put ?????? into string match it would match against any single characters. How can I make it match the question mark sign?

Would it be: *!*\?\?\?\?\?\?\?\?*@*
By adding an extra slash infront of each question mark?

[#2] Also I want to know the best way to match numerical format ips and their reverses.

##EXAMPLE##
IP: 202.125.84.12
Resolved: host-123-745.cable.interpacket.net

How can I check to see if a ban is made only in the D, B and C (D.B.C.*) range format of the numerical ip and not resolved ip.

Like the ranges are in:
202.125.84.12
D.C.B.A

{([string match -nocase "*\[0-9\].*\[0-9\].*\[0-9\].*" [lindex [split $uhost "@"] 1]])}

And how can I differentiate between a numerical and a resolved one? Matching alphabets in the resolved in? And only numbers in the numerical one?

The thing is the numerical A, B, C, D ranges can contain sometimes 1, 2 or 3 numericals. So how to match all those combinations:

\[0-9\] or \[0-9\]\[0-9\] or \[0-9\]\[0-9\]\[0-9\]

The same goes for resolved IP's. When and where to match alphabets? Maybe split and match the last one (The domain .com, .net, .org, .ca, .us etc). But then again we wouldn't be able to differentiate from vhosts. We would need to match numbers and characters both in resolved addresses.

If anyone can guide me to implement this simple logic would be a thumbs up for them! ;)

(P.S: I am terrible with REGEXP, so don't say implement it with that!)
·­awyeah·

==================================
Facebook: jawad@idsia.ch (Jay Dee)
PS: Guys, I don't accept script helps or requests personally anymore.
==================================
User avatar
demond
Revered One
Posts: 3073
Joined: Sat Jun 12, 2004 9:58 am
Location: San Francisco, CA
Contact:

Re: String matching (using string match)

Post by demond »

awyeah wrote: (P.S: I am terrible with REGEXP, so don't say implement it with that!)
for what you want to do, you have to learn & use regexps effectively

even if you manage to come up with a [string match] solution, it would be uglier and heavier than a regexp one (for your specific need; I'm not generalizing)
User avatar
awyeah
Revered One
Posts: 1580
Joined: Mon Apr 26, 2004 2:37 am
Location: Switzerland
Contact:

Post by awyeah »

Hehe, yeah thanks I know but that wasn't much of help either. REGEXP for some matching is easy and for complexity its like a way too long method of TRIAL and ERROR.

Plus its slow so I wanted to use string match over here.
·­awyeah·

==================================
Facebook: jawad@idsia.ch (Jay Dee)
PS: Guys, I don't accept script helps or requests personally anymore.
==================================
O
Ofloo
Owner
Posts: 953
Joined: Tue May 13, 2003 1:37 am
Location: Belguim
Contact:

Post by Ofloo »

might seen crappy bit it works efficiently ;)

Code: Select all

proc isipaddr {ipaddr} {
  if {[string match -nocase {} $ipaddr]} {
    return 0
  }
  foreach x [split $ipaddr \x2E] {
    if {![regexp ^\[0-9\]+$ $x]} {
      return 0
    } elseif {$x > 255} {
      return 0
    }
    if {[info exists i]} {
      incr i
    } else {
      set i 1
    }
  }
  if {$i != 4} {
    return 0
  } else {
    return 1
  }
}
there is an ishost in there to if u like ..

http://cvs.ofloo.net/ip-to-country/ip-t ... cvs-markup
Last edited by Ofloo on Sun Oct 24, 2004 1:48 pm, edited 1 time in total.
XplaiN but think of me as stupid
g
greenbear
Owner
Posts: 733
Joined: Mon Sep 24, 2001 8:00 pm
Location: Norway

Post by greenbear »

or you can use the testip proc that comes with alltools.tcl
User avatar
awyeah
Revered One
Posts: 1580
Joined: Mon Apr 26, 2004 2:37 am
Location: Switzerland
Contact:

Post by awyeah »

Code: Select all

proc ishost {host} {
  foreach {a b} [split [reverse_string $host] \x2E] break
  if {[regexp -all {[a-zA-Z]} $a] && [regexp -all {[a-zA-Z0-9]} $b]} {
    if {![string match -nocase {} $a] && ![string match -nocase {} $b]} {
      return 1
    } else {
      return 0
    }
  } else {
    return 0
  }
}
Ah just what I need...
Thanks for the help both of you Ofloo and gb!
(I'll look into alltools.tcl as well)
·­awyeah·

==================================
Facebook: jawad@idsia.ch (Jay Dee)
PS: Guys, I don't accept script helps or requests personally anymore.
==================================
Locked