Re: Regular Expression to search for double occurence of a pattern
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.tcl archive

Re: Regular Expression to search for double occurence of a pattern

From: Eckhard Lehmann <ecky-l@web.de>
Date: Fri Oct 28 2005 - 21:05:27 CEST

ink.paint@gmail.com schrieb:
> Hi
>
> What would be the best method to search a string for double occurance
> of a pattern.
>
> Ex: set mystr "my name is your name only"
>

regexp -all {name} $mystr

gives you the count of occurences.

> now i have the word "name" occuring twice in 'mystr'.
> What is the method to count the occurance of word "name" ?
> or if i want to make sure it occurs twice what is the method ?

You want to try:

if {[regexp -all {name} $mystr] == 2} {
     # do it
}

Eckhard
Received on Mon Nov 21 00:36:49 2005