Re: regexp again :( i am about to explode.....
- From: "EKB" <eric@xxxxxxxxxxxxxxx>
- Date: 10 Feb 2007 18:40:45 -0800
On Feb 9, 10:23 am, Glenn Jackman <gle...@xxxxxx> wrote:
At 2007-02-09 08:58AM, "SuNnY" wrote:
this is what i have in my code..
set Pattern {\mport #[0x0-9a-fA-F]}
You might want to use {\mport #(?:0[xX])?[[:xdigit:]]+}
puts $Pattern
foreach Str [fileutil::grep $Pattern [fileutil::find $RootDir
{string match *.inform}]] { ;#<====== this works fine, as Str has
all those lines where $Pattern occurs.
puts "$Str" ;#<==== Example of the problem
port #fa56 lets see it through <===content of single line file
set patMat [lsearch -exact -inline -all -regexp $Str {[port[ ]+[\#]
[a-fA-F0-9]+]}] ;#<====== works absolutely the way i want it to
when tried at wish console
doesnt match anything when tried to run the script. $patMat its empty.
You want just this:
set patMat [regexp $Pattern $Str]
$Str is a string, not a list[*], so don't use list commands
(i.e. lsearch) on it.
([*] not _necessarily_ a list)
Why are you using {[port[ ]+[\#][a-fA-F0-9]+]} instead of $Pattern?
-------------------^------------------------^
You have too many brackets there.
If $Str eq "Example of the problem port #fa56 lets see it thorugh"
then essentially your lsearch command is looking for the pattern
{port #[[:xdigit:]] in the list
{{Example} {of} {the} {problem} {port} {#fa56} {...}}
None of the elements of that list contain a space character, so the
pattern will not be matched.
***its definitely matching "port#af56" when i write set
patMat[lsearch.............-regexp $Str {[port#[a-fA-F0-9]+]}]
I don't doubt it. Because your pattern is surrounded by square brackets,
you're really looking for any words in the list that contain any of
these characters:
][+#0123456789ABCDEFabcdefoprt
which will match "Example", "of", "the", "problem", "port", and "#fa56".
You really need to learn about regular expressions. You can't just
throw brackets into a pattern hoping it will magically start working.
--
Glenn Jackman
"You can only be young once. But you can always be immature." -- Dave Barry
Just checking, but are you trying to match more than one space or
whitespace character? In that case, use \s+ (for one or more
whitespace characters) or \s* (for zero or more whitespace
characters).
.
- References:
- regexp again :(
- From: SuNnY
- Re: regexp again :(
- From: Cameron Laird
- Re: regexp again :(
- From: SuNnY
- Re: regexp again :(
- From: suchenwi
- Re: regexp again :( i am about to explode.....
- From: SuNnY
- Re: regexp again :( i am about to explode.....
- From: Glenn Jackman
- regexp again :(
- Prev by Date: Re: More on byte compilation
- Next by Date: Re: Suggestions? Blocking user input while application is busy.
- Previous by thread: Re: regexp again :( i am about to explode.....
- Next by thread: Re: regexp again :( i am about to explode.....
- Index(es):
Relevant Pages
|
|