Re: regexp again :(
- From: "suchenwi" <richard.suchenwirth-bauersachs@xxxxxxxxxxx>
- Date: 9 Feb 2007 00:42:20 -0800
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
.
- Follow-Ups:
- Re: regexp again :( i am about to explode.....
- From: SuNnY
- Re: regexp again :( i am about to explode.....
- References:
- regexp again :(
- From: SuNnY
- Re: regexp again :(
- From: Cameron Laird
- Re: regexp again :(
- From: SuNnY
- regexp again :(
- Prev by Date: Re: Expect: The System has no more ptys
- Next by Date: Re: Extract groups of like numbers from list
- Previous by thread: Re: regexp again :(
- Next by thread: Re: regexp again :( i am about to explode.....
- Index(es):
Relevant Pages
|
|