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.

Help about regexp syntax

Old posts that have not been replied to for several years.
Locked
c
cerberus_gr
Halfop
Posts: 97
Joined: Fri Feb 07, 2003 8:57 am
Location: 127.0.0.1

Help about regexp syntax

Post by cerberus_gr »

Hello,

Because I can't understand regexp could someone help me?

I want to use regexp in order to check if two words are in a sentence.
What I mean...

I have the lines:
abc def ghi jkl
abc dek jjs kks
abd jjs hsh ghi

and I want to search for abc AND ghi. I want to use regexp and this to return only 1st line.

What Should I do?

In mirc scripting this command is string1*string2, where * can contain 0 or more chrs. I want the same "method" for the regexp...
User avatar
strikelight
Owner
Posts: 708
Joined: Mon Oct 07, 2002 10:39 am
Contact:

Post by strikelight »

you could use regexp, but 'string match' is more suited for this type of problem.

Code: Select all

if {[string match "*abc*ghi*" $line]} { ... abc and ghi are in this line ... }
c
cerberus_gr
Halfop
Posts: 97
Joined: Fri Feb 07, 2003 8:57 am
Location: 127.0.0.1

Post by cerberus_gr »

I want to use grep command of linux so I need this syntax. Grep command has the same syntax as regexp.

Is there any better way to search 4 folders with 100 files each one for a string than grep command?

Thx
User avatar
strikelight
Owner
Posts: 708
Joined: Mon Oct 07, 2002 10:39 am
Contact:

Post by strikelight »

Since this is a tcl forum, I recommend taking a look at the "glob" command in the TCL manpages, instead of talking about unix commands.
c
cerberus_gr
Halfop
Posts: 97
Joined: Fri Feb 07, 2003 8:57 am
Location: 127.0.0.1

Post by cerberus_gr »

In a code i can use unix commands, such as lynx, wget etc. A lot of tcl scripts have one "clean" unxi command. So why is this a problem if I use the grep command.

Althought I have tcl 8.0 and glob has just one option :(
Is the glob command so quick as the grep is?

Sorry, if my post isn't about tcl :(
c
cvanmeer
Halfop
Posts: 40
Joined: Tue Dec 02, 2003 1:00 pm
Location: The Netherlands
Contact:

Post by cvanmeer »

here is a lil thingie to help you get started.

Code: Select all

  set lookup [open "|/bin/grep -R #TINGIE YOU WANT TO SEARCH FOR# $arg"]
  while {![eof $lookup]} {
   catch {set result [gets $lookup]}
   putserv "PRIVMSG $nick :$result"
  }
   catch {close $lookup}
   return 1
hope it helps.

gr.
Chris
c
cerberus_gr
Halfop
Posts: 97
Joined: Fri Feb 07, 2003 8:57 am
Location: 127.0.0.1

Post by cerberus_gr »

Thx a lot, it's working :)
Locked