Re: regexp again :(



On 9 Feb., 06:00, "SuNnY" <esu...@xxxxxxxxx> wrote:
How do we match white space " " (single white space), which occurs
between two characters.

For ex if have to match "A C" or "A 5"

I am trying to form a regexp pattern.

will this work ??? set pattern {^[A-Z] [0-9]$} to match "A 0" or "B 4"
or "C 6" "W 456"

The best one to ask "will this work?" is an interactive tclsh :^)
Start tclsh without arguments, type your commands at the % prompt, see
what comes out.


I tried putting \s, "\s", [ \s] every other combination to match for
single white space....just could not get what i wanted.

if pattern is something like this "A #A" or "Aa #B12" or "ffg #3456"
without trying to match white space, i could do easily ...but the
moment i try to match white space...it just dont do....

tcl man herehttp://www.tcl.tk/man/tcl8.5/TclCmd/re_syntax.htm#M58do
define "\s" to be white space....then why it doesn't work??

I think you should read the man page http://www.tcl.tk/man/tcl8.4/TclCmd/Tcl.htm
in detail. Your problem is that re_syntax and Tcl are different
languages. In "\s", the Tcl parser sees the backslash, decides that it
not part of a defined escape sequence (like \n, \t etc.), and discards
it, so the string that goes into regexp is just "s".

To avoid such substitutions (others happen on $ and [...], put braces
around the regular expression. This is not a special rule, but holds
throughout Tcl. The 11 rules on that man page (12 from 8.5) should be
very clear to coder... saves tremendous time...

Here's some interactive experimenting with the issue:
$ tclsh
% regexp "A\sb" "A b"
0
% regexp {A\sb} "A b"
1
% puts "A\sb"
Asb
% puts {A\sb}
A\sb

.



Relevant Pages

  • Re: regexp again :( i am about to explode.....
    ... Start tclsh without arguments, type your commands at the % prompt, see ... without trying to match white space, i could do easily ...but the ... Your problem is that re_syntax and Tcl are different ...
    (comp.lang.tcl)
  • Re: Perl like "warnings"
    ... :>> When I write Perl scripts I can do a syntax check from the command line ... :>> Does Tcl have the equivalent? ... :> No tclsh does not have this. ... It would provide at least a first pass at locating various syntax errors. ...
    (comp.lang.tcl)
  • Re: Delete a text file
    ... >Is it possible to delete a text file with TCL? ... must be atime, attributes, channels, copy, delete, ...
    (comp.lang.tcl)
  • Re: C++/Tcl/C++ Interface
    ... retrieve them in a convenient format. ... This isn't "diving into the guts of Tcl", it is using the Tcl API in the ... In tclsh if I load GL.so, ... In case I know package name, then I guess Tcl_PkgRequire might solve ...
    (comp.lang.tcl)
  • Parsing arguments in C extension
    ... As part of a large project, I need to write a family of extension ... verbs for the Tcl interpreter -- that's tclsh, ... This is pretty much the same syntax as all existing Tcl ...
    (comp.lang.tcl)