Re: regexp again :( i am about to explode.....



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).

.



Relevant Pages

  • Re: WILDCARD: output all a* by searching a text file
    ... where * denotes a string of characters. ... When you want to write a program that search a pattern such as /a./ ... int main{ ... int main(int argc,const char** argv){ ...
    (comp.programming)
  • Re: Expert script (.bat) writers help needed (strip double-quote from string)
    ... Sets or returns the regular expression pattern being searched for. ... Always a RegExp object variable. ... May include any of the regular expression characters defined in the table in the Settings section. ...
    (microsoft.public.windowsxp.help_and_support)
  • Re: First round of descriptive/external exercises
    ... I don't see coming up with that sort of omni pattern by ... The Mason/Della lie thing has ALWAYS been about ... >stuff, because you're nearly always dealing with two or more characters, ... lie to fit her action. ...
    (rec.arts.sf.composition)
  • Re: RegEx: How to ignore the number of whitespaces?
    ... matching character sequences in strings. ... what are the limitations of the "arbitrary Unicode characters?" ... Exactly one of them must be found in the string, ... Certain subsequences of a pattern may be marked as optional. ...
    (microsoft.public.dotnet.framework)
  • Re: Efficient String Lookup?
    ... regexp language allowed embedded Perl code, ... The pattern is ... So the regexp engine tries the next option, ... I could put it inside a * to match all characters, ...
    (comp.lang.python)