gives a list of 7 items : dum dummy a b c d c4
gives a list of " items : c c
regexp -inline -all {\S+} "dum dummy a b c d c4"
On 10/14/26 17:05, Olivier wrote:
regexp -inline -all {\S+} "dum dummy a b c d c4"
Did you mean to do:
regexp -inline -all {\s+} "dum dummy a b c d c4"
Note the lower case character "s".
Erik Leunissen
Hello,
Simply :
set _res [regexp -inline -all {\S+} "dum dummy a b c d c4"]
gives a list of 7 items : dum dummy a b c d c4
set _res [regexp -inline -all {c+} "dum dummy a b c d c4"]
gives a list of " items : c c
I understand that {c+} acts as a specification, but I cannot understand why {\S+}
acts as a counter-specification, it should return only spaces and/or tabs ?
I found this "trick" on https://wiki.tcl-lang.org/page/Get+a+Certain+Line+From+a+File I often
deal with simulation data where items of line are homogeneously
separated either by space or by tab. So the line can be considered
as a list. But in rare case you stumble on hybrid separators : line defining units or names for instance, that is how I came to this
question. And this "trick" works as a charm !
Erik Leunissen <[email protected]> posted:
On 10/14/26 17:05, Olivier wrote:
regexp -inline -all {\S+} "dum dummy a b c d c4"
Did you mean to do:
regexp -inline -all {\s+} "dum dummy a b c d c4"
Note the lower case character "s".
Erik Leunissen
Ah ! Thank you, your message makes me look (again) at the definition
of \S with an uppercase : \S <==> [^[:space:]] . I did not pay
attention to the "^" wich means : "If the list begins with “^”, it matches any single character (but see below) not from the rest of the
list."
The behaviour is now obvious ! It was in the documentation, but I
had in mind that "^" was relative to the "beginning of", not that
usage.
Yes, it's a useful "trick" to normalize a set of "white space
separatated items" into a list, when you don't care how many white
space separaters there are, or which exact white space characters are present.
| Sysop: | DaiTengu |
|---|---|
| Location: | Appleton, WI |
| Users: | 1,142 |
| Nodes: | 10 (0 / 10) |
| Uptime: | 92:10:45 |
| Calls: | 14,704 |
| Calls today: | 2 |
| Files: | 186,497 |
| D/L today: |
2,083 files (617M bytes) |
| Messages: | 2,551,641 |